示例#1
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;
 }
     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;
     }
 }
 if (file_exists($thumb)) {
     if ($compareThumbsBySize && $thumbInfo && filesize($thumb) == $thumbInfo['size']) {
         echo 'Thumb ', $thumb, ' has same size on S3. Ignoring', "\n";
         continue;
     }
     for ($i = 1; $i <= MAX_TRIES; $i++) {
         //Upload thumb to the bucket
         $result = $s3->putObject($s3->inputFile($thumb), $bucket, $thumb, S3::ACL_PUBLIC_READ);
         if ($result) {