From aa009510beec4311f97f98e01194847620ac5586 Mon Sep 17 00:00:00 2001 From: Mikael Roos Date: Mon, 9 Feb 2015 00:40:55 +0100 Subject: [PATCH] Resize gif keeping transparency #81. --- CImage.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/CImage.php b/CImage.php index 5bb47b6..40a5f0b 100644 --- a/CImage.php +++ b/CImage.php @@ -1313,6 +1313,8 @@ class CImage $this->log("imageistruecolor() : " . (imageistruecolor($this->image) ? 'true' : 'false')); $this->log("imagecolorstotal() : " . imagecolorstotal($this->image)); $this->log("Number of colors in image = " . $this->colorsTotal($this->image)); + $index = imagecolortransparent($this->image); + $this->log("Detected transparent color = " . ($index > 0 ? implode(", ", imagecolorsforindex($this->image, $index)) : "NONE") . " at index = $index"); } return $this; @@ -1997,7 +1999,17 @@ class CImage imagealphablending($img, false); imagesavealpha($img, true); - if ($this->bgColorDefault) { + $index = imagecolortransparent($this->image); + if ($index != -1) { + + imagealphablending($img, true); + $transparent = imagecolorsforindex($this->image, $index); + $color = imagecolorallocatealpha($img, $transparent['red'], $transparent['green'], $transparent['blue'], $transparent['alpha']); + imagefill($img, 0, 0, $color); + $index = imagecolortransparent($img, $color); + $this->Log("Detected transparent color = " . implode(", ", $transparent) . " at index = $index"); + + } elseif ($this->bgColorDefault) { $color = $this->getBackgroundColor($img); imagefill($img, 0, 0, $color); @@ -2130,6 +2142,8 @@ class CImage $this->log("imageistruecolor() : " . (imageistruecolor($this->image) ? 'true' : 'false')); $this->log("imagecolorstotal() : " . imagecolorstotal($this->image)); $this->log("Number of colors in image = " . $this->ColorsTotal($this->image)); + $index = imagecolortransparent($this->image); + $this->log("Detected transparent color = " . ($index > 0 ? implode(", ", imagecolorsforindex($this->image, $index)) : "NONE") . " at index = $index"); } return $this;