Skip to content

Commit

Permalink
optimizeImage function modified to handle detect and handle multi-fra…
Browse files Browse the repository at this point in the history
…me visuals
  • Loading branch information
ozdemirrulass committed Sep 15, 2024
1 parent 6ecc788 commit 3141341
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions app/Livewire/Questions/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,23 @@ public function optimizeImage(string $path): void
$imagePath = Storage::disk('public')->path($path);
$imagick = new Imagick($imagePath);

$imagick->resizeImage(1000, 1000, Imagick::FILTER_LANCZOS, 1, true);

$imagick->stripImage();

$imagick->setImageCompressionQuality(80);
$imagick->writeImage($imagePath);
if ($imagick->getNumberImages() > 1) {
$imagick = $imagick->coalesceImages();

foreach ($imagick as $frame) {
$frame->resizeImage(1000, 1000, Imagick::FILTER_LANCZOS, 1, true);
$frame->stripImage();
$frame->setImageCompressionQuality(80);
}

$imagick = $imagick->deconstructImages();
$imagick->writeImages($imagePath, true);
} else {
$imagick->resizeImage(1000, 1000, Imagick::FILTER_LANCZOS, 1, true);
$imagick->stripImage();
$imagick->setImageCompressionQuality(80);
$imagick->writeImage($imagePath);
}

$imagick->clear();
$imagick->destroy();
Expand Down

0 comments on commit 3141341

Please sign in to comment.