Skip to content

Commit

Permalink
Fix save animated as JPG some part still black.
Browse files Browse the repository at this point in the history
  • Loading branch information
ve3 committed Apr 4, 2024
1 parent 4a6aa63 commit 3fe7642
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
12 changes: 7 additions & 5 deletions Rundiz/Image/Drivers/Imagick/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,14 @@ public function execute($file_name)

// set compression. -----------------------------
if ($check_file_ext === 'jpg' || $check_file_ext === 'webp') {
// if save to JPG or WEBP.
if ($check_file_ext === 'jpg') {
$this->fillWhiteToImage();
}
// if save as JPG or WEBP.
$this->ImagickD->jpg_quality = intval($this->ImagickD->jpg_quality);
if ($this->ImagickD->jpg_quality < 1 || $this->ImagickD->jpg_quality > 100) {
$this->ImagickD->jpg_quality = 100;
}
$this->ImagickD->Imagick->setImageCompressionQuality($this->ImagickD->jpg_quality);
} elseif ($check_file_ext === 'png') {
// if save to PNG.
// if save as PNG.
$this->ImagickD->png_quality = intval($this->ImagickD->png_quality);
if ($this->ImagickD->png_quality < 0 || $this->ImagickD->png_quality > 9) {
$this->ImagickD->png_quality = 0;
Expand Down Expand Up @@ -79,6 +76,11 @@ public function execute($file_name)
// if source image is animated.
$this->getFirstFrame();
}

if ($check_file_ext === 'jpg') {
// if save as JPG.
$this->fillWhiteToImage();
}
$save_result = $this->ImagickD->Imagick->writeImage($file_name);
}// endif;

Expand Down
8 changes: 5 additions & 3 deletions Rundiz/Image/Drivers/Imagick/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public function execute($file_ext = '')
// set compression. -----------------------------
if ($check_file_ext === 'jpg' || $check_file_ext === 'webp') {
// if show as JPG or WEBP.
if ($check_file_ext === 'jpg') {
$this->fillWhiteToImage();
}
$this->ImagickD->jpg_quality = intval($this->ImagickD->jpg_quality);
if ($this->ImagickD->jpg_quality < 1 || $this->ImagickD->jpg_quality > 100) {
$this->ImagickD->jpg_quality = 100;
Expand Down Expand Up @@ -87,6 +84,11 @@ public function execute($file_ext = '')
// if source image is animated.
$this->getFirstFrame();
}

if ($check_file_ext === 'jpg') {
// if show as JPG.
$this->fillWhiteToImage();
}
$this->ImagickD->Imagick->setImageFormat($check_file_ext);
$show_result = $this->ImagickD->Imagick->getImageBlob();
}// endif;
Expand Down
2 changes: 1 addition & 1 deletion Rundiz/Image/Drivers/Traits/ImagickTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait ImagickTrait
*/
protected function fillWhiteToImage()
{
$this->ImagickD->Imagick->setImageBackgroundColor('white');
$this->ImagickD->Imagick->setImageBackgroundColor(new \ImagickPixel('white'));
$this->ImagickD->Imagick->setImageAlphaChannel(\Imagick::ALPHACHANNEL_REMOVE);
}// fillWhiteToImage

Expand Down

0 comments on commit 3fe7642

Please sign in to comment.