/** * 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.'); }
/** * Scales an image according to an image template, and stores it. * * @param String $filename Filename of the source image * @param Int $id Id of the database record corresponding to this image file * @param String $template Name of the template, if left empty, scaled versions for all templates will be generated. **/ public function scaleAndStore($filename, $id, $template = null, $overwrite = false) { $templates = !is_null($template) ? (array) $template : ($templates = $this->getTemplateNames()); $file = new Garp_Image_File(Garp_File::FILE_VARIANT_UPLOAD); $sourceData = $file->fetch($filename); $imageType = $file->getImageType($filename); foreach ($templates as $template) { $this->_scaleAndStoreForTemplate($sourceData, $imageType, $id, $template, $overwrite); } }