public function testCanOptimizePng() { $pngQuant = new Garp_Image_PngQuant(); if (!$pngQuant->isAvailable()) { return; } $sourcePath = $this->_getMockImagePath(); $sourceData = file_get_contents($sourcePath); $targetData = $pngQuant->optimizeData($sourceData); $this->assertLessThan(strlen($sourceData), strlen($targetData)); }
/** * Optimize images * * @param array $args * @return bool success */ public function optimize($args) { $imageModel = new Model_Image(); $pngs = $imageModel->fetchAll($imageModel->select()->from($imageModel->getName(), array('filename'))->where('filename LIKE ?', '%.png')); $pngQuant = new Garp_Image_PngQuant(); if (!$pngQuant->isAvailable()) { Garp_Cli::errorOut('I have no business here: pngquant is not available.'); } $gif = new Garp_Image_File(); foreach ($pngs as $png) { $data = $gif->fetch($png->filename); $data = $pngQuant->optimizeData($data); $gif->store($png->filename, $data, true); Garp_Cli::lineOut('Optimized ' . $png->filename); } Garp_Cli::lineOut('Done.'); }
/** * @return Array The passed parameters. */ protected function _beforeStore($filename, $data, $overwrite, $formatFilename) { if ($formatFilename) { $filename = $this->_correctExtension($filename); } if ($this->_pngQuantIsEnabled()) { $pngQuant = new Garp_Image_PngQuant(); if ($pngQuant->isAvailable()) { $data = $pngQuant->optimizeData($data); } } return array($filename, $data, $overwrite, $formatFilename); }