File tree Expand file tree Collapse file tree 4 files changed +10
-9
lines changed
tests/TestSupport/TestModels Expand file tree Collapse file tree 4 files changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ class PerformManipulationsAction
14
14
public function execute (
15
15
Media $ media ,
16
16
Conversion $ conversion ,
17
- string $ imageFile
17
+ string $ imageFile,
18
18
): string {
19
19
20
20
if ($ conversion ->getManipulations ()->isEmpty ()) {
@@ -43,7 +43,7 @@ public function execute(
43
43
protected function getConversionTempFileName (
44
44
Media $ media ,
45
45
Conversion $ conversion ,
46
- string $ imageFile
46
+ string $ imageFile,
47
47
): string {
48
48
$ directory = pathinfo ($ imageFile , PATHINFO_DIRNAME );
49
49
Original file line number Diff line number Diff line change 3
3
namespace Spatie \MediaLibrary \Conversions ;
4
4
5
5
use BadMethodCallException ;
6
+ use Illuminate \Support \Arr ;
6
7
use Illuminate \Support \Traits \Conditionable ;
8
+ use Spatie \ImageOptimizer \OptimizerChainFactory ;
7
9
use Spatie \MediaLibrary \MediaCollections \Models \Media ;
8
10
use Spatie \MediaLibrary \Support \FileNamer \FileNamer ;
9
11
@@ -31,11 +33,13 @@ class Conversion
31
33
protected int $ pdfPageNumber = 1 ;
32
34
33
35
public function __construct (
34
- protected string $ name
36
+ protected string $ name,
35
37
) {
36
- // TODO: convert to jpg by default, implement optimizers
38
+ $ optimizerChain = OptimizerChainFactory:: create ( config ( ' media-library.image_optimizers ' ));
37
39
38
- $ this ->manipulations = new Manipulations ();
40
+ $ this ->manipulations = (new Manipulations ())
41
+ ->optimize ($ optimizerChain )
42
+ ->format ('jpg ' );
39
43
40
44
/*
41
45
$this->manipulations = (new Manipulations())
@@ -218,7 +222,7 @@ public function getResultExtension(string $originalFileExtension = ''): string
218
222
}
219
223
}
220
224
221
- if ($ manipulationArgument = $ this ->manipulations ->getManipulationArgument ('format ' )) {
225
+ if ($ manipulationArgument = Arr:: get ( $ this ->manipulations ->getManipulationArgument ('format ' ), 0 )) {
222
226
return $ manipulationArgument ;
223
227
}
224
228
Original file line number Diff line number Diff line change 3
3
namespace Spatie \MediaLibrary \Conversions ;
4
4
5
5
use Spatie \Image \Drivers \ImageDriver ;
6
- use Spatie \Image \Image ;
7
6
8
7
/** @mixin \Spatie\Image\Drivers\ImageDriver */
9
8
class Manipulations
Original file line number Diff line number Diff line change @@ -12,10 +12,8 @@ public function registerMediaConversions(Media $media = null): void
12
12
->width (50 )
13
13
->nonQueued ();
14
14
15
- /*
16
15
$ this ->addMediaConversion ('keep_original_format ' )
17
16
->keepOriginalImageFormat ()
18
17
->nonQueued ();
19
- */
20
18
}
21
19
}
You can’t perform that action at this time.
0 commit comments