Skip to content

Commit

Permalink
Merge pull request #615 from ozdemirrulass/fix/broken-multi-framed-vi…
Browse files Browse the repository at this point in the history
…suals-on-optimization

Fix: Broken multi framed visuals on optimization
  • Loading branch information
nunomaduro authored Sep 18, 2024
2 parents d400304 + 3141341 commit 33e5462
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 33e5462

Please sign in to comment.