Example #1
0
 public function render(Varien_Object $row)
 {
     if ($row->getFile() != '') {
         $image = Mage::getBaseUrl('media') . $row->getFile();
         return sprintf('<img src="%s" width="150px" height="100px" alt="%s"/>', $image, $this->escapeHtml($row->getTitle()));
     }
 }
Example #2
0
 public function download(Varien_Object $connectionInfo, $target)
 {
     $file = $connectionInfo->getFile();
     $this->_log($this->_getLog()->__("Connecting to FTP server %s", $connectionInfo->getHost()));
     $ftp = new Varien_Io_Ftp();
     $ftp->open(array('host' => $connectionInfo->getHost(), 'user' => $connectionInfo->getUsername(), 'password' => $connectionInfo->getPassword(), 'timeout' => $connectionInfo->hasTimeout() ? $connectionInfo->getTimeout() : 10, 'passive' => $connectionInfo->hasPassive() ? $connectionInfo->getPassive() : true, 'ssl' => $connectionInfo->hasSsl() ? $connectionInfo->getSsl() : null, 'file_mode' => $connectionInfo->hasFileMode() ? $connectionInfo->getFileMode() : null));
     if (!is_writable(Mage::getBaseDir() . DS . $target)) {
         Mage::throwException($this->_getLog()->__("Can not write file %s to %s, folder not writable (doesn't exist?)", $connectionInfo->getFile(), $target));
     }
     $this->_log($this->_getLog()->__("Downloading file %s from %s, to %s", $connectionInfo->getFile(), $connectionInfo->getHost(), $target));
     $targetPath = $this->_getTargetPath($target, basename($file));
     $ftp->read($file, $targetPath);
     $ftp->close();
 }
 /**
  * Retrieve gallery image url
  *
  * @param null|Varien_Object $image
  * @return string
  */
 public function getGalleryImageUrl($image)
 {
     if ($image) {
         $helper = $this->helper('catalog/image')->init($this->getProduct(), 'image', $image->getFile())->keepFrame(false);
         $size = Mage::getStoreConfig(Mage_Catalog_Helper_Image::XML_NODE_PRODUCT_BASE_IMAGE_WIDTH);
         if (is_numeric($size)) {
             $helper->constrainOnly(true)->resize($size);
         }
         return (string) $helper;
     }
     return null;
 }
 protected function _processImage($gImage = null)
 {
     list($smallThumbWidth, $smallThumbHeight) = array($this->_smallThumbWidth, $this->_smallThumbHeight);
     list($thumbWidth, $thumbHeight) = array($this->_thumbWidth, $this->_thumbHeight);
     $thumbAspectRatio = $thumbWidth / $thumbHeight;
     if (is_null($gImage)) {
         $gImage = new Varien_Object();
     }
     if ($gImage->getUnirgyImgFlag()) {
         return $gImage;
     }
     $_product = $this->getProduct();
     if ($_product->getIsProductListFlag() || $gImage->getOnlyMainUrlFlag()) {
         $imageAttr = $_product->getIsProductListFlag() ? 'small_image' : 'image';
         if ('thumb' == $gImage->getOnlyMainUrlFlag()) {
             $gImage->setThumb($this->helper('catalog/image')->init($_product, $imageAttr, $gImage->getFile())->setQuality(100)->resize($smallThumbWidth, $smallThumbHeight)->__toString());
             $gImage->setThumbSize(array($smallThumbWidth, $smallThumbHeight));
             $gImage->setMedium($gImage->getThumb());
             $gImage->setMediumSize($gImage->getThumbSize());
             $gImage->setUnirgyImgFlag(true);
         } else {
             $gImage->setMedium($this->helper('catalog/image')->init($_product, $imageAttr, $gImage->getFile())->setQuality(100)->resize($thumbWidth, $thumbHeight)->__toString());
             $gImage->setMediumSize(array($thumbWidth, $thumbHeight));
             $gImage->setUnirgyImgFlag(true);
         }
         return $gImage;
     }
     $imgHlp = $this->helper('catalog/image')->init($_product, 'image', $gImage->getFile())->setQuality(100);
     $imgHlp->__toString();
     list($imgWidth, $imgHeight) = $imgHlp->getOriginalSizeArray();
     if (!$imgHeight) {
         $imgHeight = 1;
     }
     $maxDim = max($imgWidth, $imgHeight);
     if ($maxDim > 2000) {
         $resizeRatio = $maxDim / 2000;
         $imgWidth = round($imgWidth / $resizeRatio);
         $imgHeight = round($imgHeight / $resizeRatio);
     }
     $imgAspectRatio = $imgWidth / $imgHeight;
     if ($imgAspectRatio > $thumbAspectRatio) {
         $imgHeight = round($imgWidth / $thumbAspectRatio);
         $zoomValue = $imgWidth / $thumbWidth;
     } else {
         $imgWidth = round($imgHeight * $thumbAspectRatio);
         $zoomValue = $imgHeight / $thumbHeight;
     }
     $midZoomValue = 1 + ($zoomValue - 1) / 2;
     $midImgWidth = round($thumbWidth * $midZoomValue);
     $midImgHeight = round($thumbHeight * $midZoomValue);
     if ($imgWidth < $thumbWidth || $imgHeight < $thumbHeight) {
         $midImgWidth = $imgWidth = $thumbWidth;
         $midImgHeight = $imgHeight = $thumbHeight;
     }
     list($img, $midImg, $medium, $thumb) = array($this->helper('catalog/image')->init($_product, 'image', $gImage->getFile())->setQuality(100)->resize($imgWidth, $imgHeight)->__toString(), $this->helper('catalog/image')->init($_product, 'image', $gImage->getFile())->setQuality(100)->resize($midImgWidth, $midImgHeight)->__toString(), $this->helper('catalog/image')->init($_product, 'image', $gImage->getFile())->setQuality(100)->resize($thumbWidth, $thumbHeight)->__toString(), $this->helper('catalog/image')->init($_product, 'image', $gImage->getFile())->setQuality(100)->resize($smallThumbWidth, $smallThumbHeight)->__toString());
     $gImage->setMidImg($midImg);
     $gImage->setMidImgSize(array($midImgWidth, $midImgHeight));
     $gImage->setImg($img);
     $gImage->setImgSize(array($imgWidth, $imgHeight));
     $gImage->setMedium($medium);
     $gImage->setMediumSize(array($thumbWidth, $thumbHeight));
     $gImage->setThumb($thumb);
     $gImage->setThumbSize(array($smallThumbWidth, $smallThumbHeight));
     $gImage->setUnirgyImgFlag(true);
     return $gImage;
 }