Exemple #1
0
 /**
  * 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.');
 }
Exemple #2
0
 protected function _scaleAndStoreForTemplate($sourceData, $imageType, $id, $template, $overwrite)
 {
     $file = new Garp_Image_File(Garp_File::FILE_VARIANT_UPLOAD);
     $scaleParams = $this->getTemplateParameters($template);
     // clone this scaler, since scaling parameters are stored as class properties
     $clonedScaler = clone $this;
     $scaledImageDataArray = $clonedScaler->scale($sourceData, $scaleParams, $imageType);
     $scaledFilePath = $this->getScaledPath($id, $template);
     if ($overwrite || !$file->exists($scaledFilePath)) {
         $file->store($scaledFilePath, $scaledImageDataArray['resource'], true, false);
     }
 }