20
20
use Hyperf \Filesystem \FilesystemFactory ;
21
21
use Hyperf \HttpMessage \Exception \BadRequestHttpException ;
22
22
use Hyperf \Stringable \Str ;
23
+ use Intervention \Image \Drivers \Gd \Driver ;
23
24
use Intervention \Image \ImageManager ;
24
25
use OnixSystemsPHP \HyperfCore \Contract \CoreAuthenticatable ;
25
26
use OnixSystemsPHP \HyperfCore \Contract \CoreAuthenticatableProvider ;
@@ -42,13 +43,13 @@ trait FileRelations
42
43
* 'mimeTypes' => ['*'],
43
44
* 'presets' => [ // presets array. only for images
44
45
* '150x150' => [
45
- * 'fit ' => [150, 150],
46
+ * 'cover ' => [150, 150],
46
47
* ],
47
48
* '250x250' => [
48
- * 'fit ' => [250, 250],
49
+ * 'cover ' => [250, 250],
49
50
* ],
50
51
* '500x500' => [
51
- * 'fit ' => [500, 500],
52
+ * 'cover ' => [500, 500],
52
53
* ],
53
54
* ],
54
55
* ],
@@ -168,7 +169,7 @@ private function filterActiveFiles(array $files, bool $revert = false): array
168
169
{
169
170
return array_filter (array_map (function (File $ file ) use ($ revert ) {
170
171
$ active = empty ($ file ->deleted_at ) && empty ($ file ->delete_it );
171
- return ( $ active === ! $ revert) ? $ file ->id : null ;
172
+ return $ active === ! $ revert ? $ file ->id : null ;
172
173
}, $ files ));
173
174
}
174
175
@@ -223,23 +224,24 @@ private function generateImagePresets(File $file, array $params, ConfigInterface
223
224
$ filesystem = ApplicationContext::getContainer ()->get (FilesystemFactory::class)->get ($ storage );
224
225
$ publicPathPrefix = $ config ->get ("file_upload.storage. {$ storage }.public_path_prefix " , '' );
225
226
$ storagePathPrefix = $ config ->get ("file_upload.storage. {$ storage }.storage_path_prefix " , '' );
226
- $ manager = new ImageManager (['driver ' => 'gd ' ]);
227
+ $ imageDriver = $ config ->get ('file_upload.driver ' , Driver::class);
228
+ $ manager = new ImageManager ($ imageDriver );
227
229
foreach ($ params ['presets ' ] as $ preset => $ options ) {
228
230
$ extension = pathinfo ($ file ->name , PATHINFO_EXTENSION );
229
231
$ presetName = "{$ preset }. {$ extension }" ;
230
232
$ destination = $ file ->path . DIRECTORY_SEPARATOR . $ presetName ;
231
233
if ($ filesystem ->fileExists ($ destination )) {
232
234
continue ;
233
235
}
234
- $ intImage = $ manager ->make ($ filesystem ->read ($ file ->full_path ));
236
+ $ intImage = $ manager ->read ($ filesystem ->read ($ file ->full_path ));
235
237
foreach ($ options as $ action => $ params ) {
236
238
if (is_callable ($ params )) {
237
239
$ intImage = $ params ($ intImage , $ filesystem ->read ($ file ->full_path ));
238
240
} else {
239
241
$ intImage = call_user_func_array ([$ intImage , $ action ], $ params );
240
242
}
241
243
}
242
- $ filesystem ->write ($ destination , $ intImage ->encode ()->getEncoded (), [] );
244
+ $ filesystem ->write ($ destination , $ intImage ->encode ()->toString () );
243
245
$ publicDestination = $ publicPathPrefix . Str::after ($ destination , $ storagePathPrefix );
244
246
$ file ->addPreset ($ preset , "{$ file ->domain }{$ publicDestination }" );
245
247
}
0 commit comments