Skip to content

Commit 2bee2a9

Browse files
committed
fix: aggiornamento libreria image
1 parent 66df28d commit 2bee2a9

6 files changed

Lines changed: 52 additions & 38 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"guzzlehttp/guzzle": "^7.0.1",
3939
"ifsnop/mysqldump-php": "^2.3",
4040
"illuminate/database": "^8.0",
41-
"intervention/image": "^2.3",
41+
"intervention/image": "^3.11",
4242
"jurosh/pdf-merge": "^2.1",
4343
"league/csv": "^9.7.0",
4444
"league/flysystem": "^3.0",

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ function wacom(){
279279
'poly2tri/dist/poly2tri.js',
280280
'protobufjs/dist/protobuf.min.js',
281281
'jszip/dist/jszip.min.js',
282-
'gl-matrix/dist/gl-matrix.min.js',
282+
'gl-matrix/gl-matrix-min.js',
283283
'rbush/rbush.min.js',
284284
'sjcl/sjcl.js',
285285
'node-forge/dist/forge.min.js'

modules/interventi/actions.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
use Plugins\ComponentiImpianti\Componente;
4242
use Plugins\ListinoClienti\DettaglioPrezzo;
4343
use Plugins\PianificazioneInterventi\Promemoria;
44+
use Intervention\Image\ImageManager;
45+
use Intervention\Image\Drivers\Imagick\Driver;
4446

4547
$id_modulo_impianti = Module::where('name', 'Impianti')->first()->id;
4648
$plugin_impianti = Plugin::where('name', 'Impianti')->first()->id;
@@ -745,14 +747,14 @@
745747

746748
$data = explode(',', post('firma_base64'));
747749

748-
$img = Intervention\Image\ImageManagerStatic::make(base64_decode($data[1]));
749-
$img->resize(680, 202, function ($constraint) {
750-
$constraint->aspectRatio();
751-
});
750+
$manager = ImageManager::gd();
751+
$img = $manager->read(base64_decode($data[1]));
752+
753+
$img->scale(680, 202);
752754

753755
if (setting('Sistema di firma') == 'Tavoletta Wacom') {
754-
$img->brightness(setting('Luminosità firma Wacom'));
755-
$img->contrast(setting('Contrasto firma Wacom'));
756+
$img->brightness((float)setting('Luminosità firma Wacom'));
757+
$img->contrast((float)setting('Contrasto firma Wacom'));
756758
}
757759

758760
if (!$img->save(base_dir().'/files/interventi/'.$firma_file)) {
@@ -833,10 +835,9 @@
833835

834836
$data = explode(',', post('firma_base64'));
835837

836-
$img = Intervention\Image\ImageManagerStatic::make(base64_decode($data[1]));
837-
$img->resize(680, 202, function ($constraint) {
838-
$constraint->aspectRatio();
839-
});
838+
$manager = ImageManager::gd();
839+
$img = $manager->read(base64_decode($data[1]));
840+
$img->scale(680, 202);
840841

841842
if (!$img->save(base_dir().'/files/interventi/'.$firma_file)) {
842843
flash()->error(tr('Impossibile creare il file!'));

src/API/App/v1/Interventi.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222

2323
use API\App\AppResource;
2424
use Carbon\Carbon;
25-
use Intervention\Image\ImageManagerStatic;
2625
use Modules\Anagrafiche\Anagrafica;
2726
use Modules\Interventi\Intervento;
2827
use Modules\Interventi\Stato;
2928
use Modules\TipiIntervento\Tipo as TipoSessione;
29+
use Intervention\Image\ImageManager;
30+
use Intervention\Image\Drivers\Imagick\Driver;
3031

3132
class Interventi extends AppResource
3233
{
@@ -378,10 +379,9 @@ protected function salvaFirma($firma_base64)
378379

379380
$data = explode(',', (string) $firma_base64);
380381

381-
$img = ImageManagerStatic::make(base64_decode($data[1]));
382-
$img->resize(680, 202, function ($constraint) {
383-
$constraint->aspectRatio();
384-
});
382+
$manager = ImageManager::gd();
383+
$img = $manager->read(base64_decode($data[1]));
384+
$img->scale(680, 202);
385385

386386
$img->save(base_dir().'/files/interventi/'.$firma_file);
387387

src/Models/Upload.php

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222

2323
use Common\SimpleModelTrait;
2424
use Illuminate\Database\Eloquent\Model;
25-
use Intervention\Image\ImageManagerStatic;
2625
use Modules\FileAdapters\FileAdapter;
2726
use Modules\FileAdapters\OSMFilesystem;
27+
use Intervention\Image\ImageManager;
28+
use Intervention\Image\Drivers\Imagick\Driver;
2829

2930
class 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

src/Models/User.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222

2323
use Common\SimpleModelTrait;
2424
use Illuminate\Database\Eloquent\Model;
25-
use Intervention\Image\ImageManagerStatic;
25+
use Intervention\Image\ImageManager;
26+
use Intervention\Image\Drivers\Imagick\Driver;
2627
use Modules\Anagrafiche\Anagrafica;
2728

2829
class User extends Model
@@ -171,12 +172,9 @@ public function setPhotoAttribute($value)
171172
$file = base_dir().'/files/temp_photo.'.$info['extension'];
172173

173174
// Ridimensionamento
174-
$driver = extension_loaded('gd') ? 'gd' : 'imagick';
175-
ImageManagerStatic::configure(['driver' => $driver]);
176-
177-
$img = ImageManagerStatic::make($filepath)->resize(100, 100, function ($constraint) {
178-
$constraint->aspectRatio();
179-
});
175+
$manager = ImageManager::gd();
176+
$img = $manager->read($filepath);
177+
$img->scale(100, 100);
180178
$img->save(slashes($file));
181179

182180
// Aggiunta nuova foto

0 commit comments

Comments
 (0)