Esempio n. 1
0
File: Gd2.php Progetto: mygento/cdn
 private function uploadfile($source, $fileName, $destination, $newName)
 {
     $adapter = Mage::getModel('mycdn/adapter');
     $result = $adapter->uploadFileAsync($source, $fileName, null, 0);
     if (!$result) {
         return parent::save($destination, $newName);
     }
     return $result;
 }
Esempio n. 2
0
 /**
  * get the image processor
  *
  * @access protected
  * @return Varien_Image_Adapter_Gd2
  * @author Ultimate Module Creator
  */
 protected function _getImageProcessor()
 {
     if (is_null($this->_imageProcessor)) {
         $this->_imageProcessor = Varien_Image_Adapter::factory('GD2');
         $this->_imageProcessor->keepFrame($this->_keepFrame);
         $this->_imageProcessor->keepAspectRatio($this->_keepAspectRatio);
         $this->_imageProcessor->constrainOnly($this->_constrainOnly);
     }
     return $this->_imageProcessor;
 }
Esempio n. 3
0
 /**
  * Hijacks the normal GD2 save method to add ImageCDN hooks. Fails back to parent method
  * as appropriate.
  *
  * @param string $destination
  * @param string $newName
  * @return none
  */
 public function save($destination = null, $newName = null)
 {
     $cds = Mage::Helper('imagecdn')->factory();
     $compression = Mage::getStoreConfig('imagecdn/general/compression');
     if ($cds->useCdn()) {
         $temp = tempnam(sys_get_temp_dir(), 'cds');
         parent::save($temp);
         //Compress images?
         if ($this->_fileType == IMAGETYPE_JPEG && $compression > 0) {
             $convert = round((9 - $compression) * (100 / 8));
             //convert to imagejpeg's scale
             call_user_func('imagejpeg', $this->_imageHandler, $temp, $convert);
         } elseif ($this->_fileType == IMAGETYPE_PNG && $compression > 0) {
             $convert = round(($compression - 1) * (9 / 8));
             //convert to imagepng's scale
             call_user_func('imagepng', $this->_imageHandler, $temp, $convert);
         }
         $filename = !isset($destination) ? $this->_fileName : $destination;
         if (isset($destination) && isset($newName)) {
             $filename = $destination . "/" . $filename;
         } elseif (isset($destination) && !isset($newName)) {
             $info = pathinfo($destination);
             $filename = $destination;
             $destination = $info['dirname'];
         } elseif (!isset($destination) && isset($newName)) {
             $filename = $this->_fileSrcPath . "/" . $newName;
         } else {
             $filename = $this->_fileSrcPath . $this->_fileSrcName;
         }
         if ($cds->save($filename, $temp)) {
             @unlink($temp);
         } else {
             if (!is_writable($destination)) {
                 try {
                     $io = new Varien_Io_File();
                     $io->mkdir($destination);
                 } catch (Exception $e) {
                     throw new Exception("Unable to write file into directory '{$destinationDir}'. Access forbidden.");
                 }
             }
             @rename($temp, $filename);
             @chmod($filename, 0644);
         }
     } else {
         return parent::save($destination, $newName);
     }
 }
Esempio n. 4
0
 public static function imageResize($image, $width = 100, $height = 100)
 {
     $newName = $width . 'x' . $height . '_' . $image;
     $basePath = self::getRealImageFolderPath();
     if (file_exists($basePath . $newName)) {
         return $newName;
     }
     if (class_exists('Varien_Image_Adapter_Gd2')) {
         try {
             $_image = new Varien_Image_Adapter_Gd2();
             $_image->open($basePath . $image);
             $_image->keepAspectRatio(true);
             $_image->resize($width, $height);
             if (Mage::helper('awfeatured')->checkVersion('1.4')) {
                 $_image->save($basePath, $newName);
             } else {
                 $_image->save(null, $newName);
             }
             return $newName;
         } catch (Exception $ex) {
             Mage::logException($ex);
             return false;
         }
     }
     return false;
 }
 } else {
     echo 'File ', $image, ' was already downloaded', "\n";
 }
 $dispersionPath = substr($image, $imgPrefixLen);
 foreach ($dimensions as $thumbPrefix => $dimension) {
     $thumb = $thumbPrefix . $dispersionPath;
     $thumbInfo = $s3->getObjectInfo($bucket, $thumb, $compareThumbsBySize);
     //Check if thumb exists in the bucket
     if ($thumbInfo && !$_reuploadThumbs) {
         echo 'Thumb ', $thumb, ' exists', "\n";
         continue;
     }
     if (!file_exists($thumb) || $recalculateThumbs) {
         //Create directories for the thumb
         createDirectory(substr($thumb, 0, strlen($thumbPrefix) + 4));
         $adapter = new Varien_Image_Adapter_Gd2();
         //Default settings from Mage
         $adapter->keepAspectRatio(true);
         $adapter->keepFrame(false);
         $adapter->keepTransparency(true);
         $adapter->constrainOnly(true);
         $adapter->backgroundColor(array(255, 255, 255));
         $adapter->quality(100);
         try {
             $adapter->open($image);
             $adapter->resize($dimension['width'], $dimension['height']);
             $adapter->save($thumb);
         } catch (Exception $e) {
             echo 'Can\'t resize ', $image, ' (', $e->getMessage(), ')', "\n";
             continue;
         }