diff --git a/src/GifFrameExtractor/GifFrameExtractor.php b/src/GifFrameExtractor/GifFrameExtractor.php index 3ecac89..f1386bb 100644 --- a/src/GifFrameExtractor/GifFrameExtractor.php +++ b/src/GifFrameExtractor/GifFrameExtractor.php @@ -1,6 +1,6 @@ reset(); @@ -141,30 +141,32 @@ public function extract($filename, $originalFrames = false) if ($i > 0) { $prevImg = $this->frames[$i - 1]['image']; + $sprite = imagecreate($this->gifMaxWidth, $this->gifMaxHeight); + imagesavealpha($sprite, true); - } else { + $transparent = imagecolortransparent($prevImg); - $prevImg = $img; - } - - $sprite = imagecreate($this->gifMaxWidth, $this->gifMaxHeight); - imagesavealpha($sprite, true); - - $transparent = imagecolortransparent($prevImg); - - if ($transparent > -1 && imagecolorstotal($prevImg) > $transparent) { + if ($transparent > -1 && imagecolorstotal($prevImg) > $transparent) { + + $actualTrans = imagecolorsforindex($prevImg, $transparent); + imagecolortransparent($sprite, imagecolorallocate($sprite, $actualTrans['red'], $actualTrans['green'], $actualTrans['blue'])); + } - $actualTrans = imagecolorsforindex($prevImg, $transparent); - imagecolortransparent($sprite, imagecolorallocate($sprite, $actualTrans['red'], $actualTrans['green'], $actualTrans['blue'])); - } - - if ((int) $this->frameSources[$i]['disposal_method'] == 1 && $i > 0) { + if ((int) $this->frameSources[$i]['disposal_method'] == 1 && $i > 0) { + + imagecopy($sprite, $prevImg, 0, 0, 0, 0, $this->gifMaxWidth, $this->gifMaxHeight); + } + $w = imagesx($img); + $h = imagesy($img); + imagecopyresampled($sprite, $img, $this->frameSources[$i]["offset_left"], $this->frameSources[$i]["offset_top"], 0, 0, $w, $h, $w, $h); + $img = $sprite; + + } else { - imagecopy($sprite, $prevImg, 0, 0, 0, 0, $this->gifMaxWidth, $this->gifMaxHeight); + $prevImg = $img; } - imagecopyresampled($sprite, $img, $this->frameSources[$i]["offset_left"], $this->frameSources[$i]["offset_top"], 0, 0, $this->gifMaxWidth, $this->gifMaxHeight, $this->gifMaxWidth, $this->gifMaxHeight); - $img = $sprite; + } $this->frameImages[$i] = $this->frames[$i]['image'] = $img;