Skip to content

Commit

Permalink
reduce gifs size
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsecas72 authored Aug 1, 2016
1 parent f07ddaf commit ea86e1b
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/Driver/GiffyDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public function giffy()
if ($index === 0 || $index === 1 || $index === 2) {
continue;
}
$frames[] = $this->getScreenshotDestination().DIRECTORY_SEPARATOR.$this->getSerializedName($this->i, $index);

$imgPath = $this->getScreenshotDestination().'/'.$this->getSerializedName($this->i, $index);
$this->convertPNGto8bitPNG($imgPath, $imgPath);
$frames[] = $imgPath;
if ($this->c - 1 === $index) {
$durations[] = 150;
continue;
Expand Down Expand Up @@ -89,6 +90,27 @@ private function saveScreenshot()
file_put_contents($screenshotFilename, parent::getScreenshot());
$this->screenshotsTaked[] = $screenshotFilename;
}

/**
* from http://stackoverflow.com/questions/13768034/php-reducing-all-image-types-quality
* @param string $sourcePath
* @param string $destPath
*/
public function convertPNGto8bitPNG($sourcePath, $destPath)
{
$srcimage = imagecreatefrompng($sourcePath);
list($width, $height) = getimagesize($sourcePath);
$img = imagecreatetruecolor($width, $height);
$bga = imagecolorallocatealpha($img, 0, 0, 0, 127);
imagecolortransparent($img, $bga);
imagefill($img, 0, 0, $bga);
imagecopy($img, $srcimage, 0, 0, 0, 0, $width, $height);
imagetruecolortopalette($img, false, 255);
imagesavealpha($img, true);
imagepng($img, $destPath);
imagedestroy($img);
}

private function highlight($xpath)
{
$styleChanged = false;
Expand Down

0 comments on commit ea86e1b

Please sign in to comment.