2222
2323use Common \SimpleModelTrait ;
2424use Illuminate \Database \Eloquent \Model ;
25- use Intervention \Image \ImageManagerStatic ;
2625use Modules \FileAdapters \FileAdapter ;
2726use Modules \FileAdapters \OSMFilesystem ;
27+ use Intervention \Image \ImageManager ;
28+ use Intervention \Image \Drivers \Imagick \Driver ;
2829
2930class Upload extends Model
3031{
@@ -374,6 +375,28 @@ public static function getInfo($file)
374375 return pathinfo ((string ) $ file );
375376 }
376377
378+ public static function ridimensionaImmagini ($ upload )
379+ {
380+ $ info = $ upload ->info ;
381+ $ directory = $ upload ->attachments_directory ;
382+
383+ $ filepath = base_dir ().'/ ' .$ info ['dirname ' ].'/ ' .$ info ['filename ' ].'. ' .$ info ['extension ' ];
384+
385+ if (!in_array (mime_content_type ($ filepath ), ['image/png ' , 'image/gif ' , 'image/jpeg ' ])) {
386+ return ;
387+ }
388+
389+ $ manager = ImageManager::gd (autoOrientation: true );
390+ $ img = $ manager ->read ($ filepath );
391+ $ img ->scale (setting ('Larghezza per ridimensionamento immagini ' ), null );
392+
393+ $ img ->save (slashes ($ filepath ));
394+
395+ clearstatcache ();
396+ $ upload ->size = filesize (slashes ($ filepath ));
397+ $ upload ->save ([], true );
398+ }
399+
377400 /**
378401 * Genera le thumbnails per le immagini.
379402 */
@@ -388,24 +411,16 @@ protected static function generateThumbnails($upload)
388411 return ;
389412 }
390413
391- $ driver = extension_loaded ('gd ' ) ? 'gd ' : 'imagick ' ;
392- ImageManagerStatic::configure (['driver ' => $ driver ]);
393-
394- $ img = ImageManagerStatic::make ($ filepath );
414+ $ manager = ImageManager::gd ();
415+ $ img = $ manager ->read ($ filepath );
416+ $ img ->scale (600 , null );
395417
396- $ img ->resize (600 , null , function ($ constraint ) {
397- $ constraint ->aspectRatio ();
398- });
399418 $ img ->save (slashes ($ directory .'/ ' .$ info ['filename ' ].'_thumb600. ' .$ info ['extension ' ]));
400419
401- $ img ->resize (250 , null , function ($ constraint ) {
402- $ constraint ->aspectRatio ();
403- });
420+ $ img ->scale (250 , null );
404421 $ img ->save (slashes ($ directory .'/ ' .$ info ['filename ' ].'_thumb250. ' .$ info ['extension ' ]));
405422
406- $ img ->resize (100 , null , function ($ constraint ) {
407- $ constraint ->aspectRatio ();
408- });
423+ $ img ->scale (100 , null );
409424 $ img ->save (slashes ($ directory .'/ ' .$ info ['filename ' ].'_thumb100. ' .$ info ['extension ' ]));
410425 }
411426
0 commit comments