public function getProfileImage() { if (isset($this->_seller['sstech_profileimage']) && ($_file_name = $this->_seller['sstech_profileimage'])) { $_media_dir = Mage::getBaseDir('media') . DS . 'customer' . DS; // Here i create a resize folder. for upload new category image $cache_dir = $_media_dir . 'resize' . DS; if (file_exists($cache_dir . $_file_name)) { $img = Mage::getBaseUrl('media') . 'customer' . DS . 'resize' . $_file_name; } elseif (file_exists($_media_dir . $_file_name)) { if (!is_dir($cache_dir)) { mkdir($cache_dir); } $_image = new Varien_Image($_media_dir . $_file_name); $_image->constrainOnly(false); $_image->keepAspectRatio(true); $_image->keepFrame(true); $_image->keepTransparency(true); $_image->backgroundColor(array(255, 255, 255)); $_image->resize(300, null); // change image height, width $_image->save($cache_dir . $_file_name); $img = Mage::getBaseUrl('media') . 'customer' . DS . 'resize' . $_file_name; } } if (!isset($img)) { $img = Mage::getBaseUrl('media') . "default_user.jpg"; } return $img; }
/** * Move the image in the fixture under magento media * directory and save a cache version of it. * * @param string $image * @return string */ protected function injectImage($image) { if (empty($image)) { return ''; } $baseImage = basename($image); $imageName = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'product' . DS . $image; $cacheImage = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'product' . DS . 'resize' . DS . $baseImage; $fixtureImage = __DIR__ . DS . 'ProductsTest' . DS . 'fixtures' . DS . $baseImage; // @see Varien_Image_Adapter_Gd2::_isMemoryLimitReached // There's a bug in Varien_Image_Adapter_Gd2::open that causes // an exception to be thrown when the PHP built in method // ini_get('memory_limit') return -1, which imply no limit. // I'm guessing that the right environment setting are not set when // running phpunit with EcomDev. if (ini_get('memory_limit') <= 0) { ini_set('memory_limit', '512M'); } $productMediaDir = str_replace($baseImage, '', $imageName); @mkdir($productMediaDir, 0777, true); // if the file already exist remove it. @unlink($imageName); // Copy the image file in our fixture directory into // Magento product media directory. @copy($fixtureImage, $imageName); $image = new Varien_Image($imageName); $image->constrainOnly(true); $image->keepAspectRatio(false); $image->keepFrame(false); $image->keepTransparency(true); $image->resize(100, 100); $image->save($cacheImage); return $imageName; }
public function resizeCategoryImage($file_name, $resize = 550) { $file_name; $resize_dir = 'resized-' . $resize; $category_dir = 'catalog' . DS . 'category'; $category_path = $_SERVER['DOCUMENT_ROOT'] . DS . 'media' . DS . $category_dir; $full_resized_url_path = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . $category_dir . DS . $resize_dir . DS; if (file_exists($category_path . DS . $resize_dir . DS . $file_name)) { return $full_resized_url_path . $file_name; } if (file_exists($category_path . DS . $file_name)) { if (!is_dir($category_path . DS . $resize_dir)) { mkdir($category_path . DS . $resize_dir); } $_image = new Varien_Image($category_path . DS . $file_name); $_image->constrainOnly(true); $_image->keepAspectRatio(false); $_image->keepFrame(false); $_image->keepTransparency(true); $_image->resize($resize); $_image->save($category_path . DS . $resize_dir . DS . $file_name); $catImg = $full_resized_url_path . $file_name; } return $catImg; }
protected function _entityImageUrl(Varien_Object $entity, $width, $height, $entityField) { $entityPath = $entity->getData($entityField); if (!$entityPath) { return null; } $dstPath = array('cache', Mage::app()->getStore()->getId(), $entityField, $width . 'x' . $height, $entityPath); $dstFile = $this->getBaseMediaPath() . DS . implode(DS, $dstPath); if (!file_exists($dstFile)) { $srcPath = array($entityPath); $srcFile = $this->getBaseMediaPath() . DS . implode(DS, $srcPath); if (!file_exists($srcFile)) { return null; } $image = new Varien_Image($srcFile); $image->keepAspectRatio(true); $image->keepTransparency(true); $image->keepFrame(true); $image->constrainOnly(false); $image->backgroundColor(array(255, 255, 255)); $image->resize($width, $height); $image->save($dstFile); } return $this->getBaseMediaUrl() . '/' . implode('/', $dstPath); }
public function getCatResizedImage($cat, $width, $height = null, $quality = 100) { if (!$cat->getThumbnail()) { return false; } $imageUrl = Mage::getBaseDir('media') . DS . "catalog" . DS . "category" . DS . $cat->getThumbnail(); if (!is_file($imageUrl)) { return false; } $imageResized = Mage::getBaseDir('media') . DS . "catalog" . DS . "category" . DS . "cache" . DS . "cat_resized" . DS . $cat->getThumbnail(); // Because clean Image cache function works in this folder only //if (! file_exists ( $imageResized ) && file_exists ( $imageUrl ) || file_exists($imageUrl) && filemtime($imageUrl) > filemtime($imageResized)) : $imageObj = new Varien_Image($imageUrl); $imageObj->constrainOnly(true); $imageObj->keepAspectRatio(true); $imageObj->keepFrame(true); // ep $imageObj->quality($quality); $imageObj->keepTransparency(true); // png $imageObj->backgroundColor(array(255, 255, 255)); $imageObj->resize($width, $height); $imageObj->save($imageResized); //endif; if (file_exists($imageResized)) { return Mage::getBaseUrl('media') . "/catalog/category/cache/cat_resized/" . $cat->getThumbnail(); } else { return $this->getImageUrl(); } }
public function resizeImg($fileName, $width = '', $height = null) { $imageURL = $this->getBaseTmpMediaUrl() . $fileName; $imagePath = $this->getBaseTmpMediaPath() . str_replace('/', DS, $fileName); $extra = $width . 'x' . $height; $newPath = $this->getBaseTmpMediaPath() . "cache" . DS . $extra . str_replace('/', DS, $fileName); //if width empty then return original size image's URL if ($width != '' && $height != '') { //if image has already resized then just return URL if (file_exists($imagePath) && is_file($imagePath) && !file_exists($newPath)) { $imageObj = new Varien_Image($imagePath); $imageObj->constrainOnly(TRUE); $imageObj->keepAspectRatio(FALSE); $imageObj->keepTransparency(true); $imageObj->keepFrame(FALSE); $imageObj->quality(100); //$width, $height - sizes you need (Note: when keepAspectRatio(TRUE), height would be ignored) $imageObj->resize($width, $height); $imageObj->save($newPath); } $resizedURL = $this->getBaseTmpMediaUrl() . "cache" . '/' . $extra . '/' . $fileName; } else { $resizedURL = $imageURL; } return $resizedURL; }
/** * Resize image * * @param string $fileName * @param int $width * @param int $height * @return string Resized image url */ public function resizeImg($fileName, $width, $height = '') { if (!$height) { $height = $width; } $thumbDir = self::IMAGE_THUMB_DIR; $resizeDir = $thumbDir . "/resized_{$width}x{$height}"; $ioFile = new Varien_Io_File(); $ioFile->checkandcreatefolder(Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . $resizeDir); $imageParts = explode('/', $fileName); $imageFile = end($imageParts); $folderURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); $imageURL = $folderURL . $fileName; $basePath = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . $fileName; $newPath = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . $resizeDir . DS . $imageFile; if ($width != '') { if (file_exists($basePath) && is_file($basePath) && !file_exists($newPath)) { $imageObj = new Varien_Image($basePath); $imageObj->constrainOnly(TRUE); $imageObj->keepAspectRatio(TRUE); $imageObj->keepFrame(FALSE); $imageObj->keepTransparency(TRUE); //$imageObj->backgroundColor(array(255,255,255)); $imageObj->resize($width, $height); $imageObj->save($newPath); } $resizedURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . $resizeDir . '/' . $imageFile; } else { $resizedURL = $imageURL; } return $resizedURL; }
public function resize($imageUrl, $width, $height) { if (!file_exists(Mage::getBaseDir('media') . DS . "catalog" . DS . "category" . DS . "resized")) { mkdir(Mage::getBaseDir('media') . DS . "catalog" . DS . "category" . DS . "resized", 0777, true); } $imageName = substr(strrchr($imageUrl, "/"), 1); if ('255,255,255' !== $this->getBackgroundColor(true)) { $imageName = $width . 'x' . $height . '/' . $this->getBackgroundColor(true) . '/' . $imageName; } else { $imageName = $width . 'x' . $height . '/' . $imageName; } $imageResized = Mage::getBaseDir('media') . DS . "catalog" . DS . "category" . DS . "resized" . DS . $imageName; $imagePath = str_replace(Mage::getBaseUrl('media'), 'media/', $imageUrl); $imagePath = Mage::getBaseDir() . DS . str_replace("/", DS, $imagePath); if (!file_exists($imageResized) && file_exists($imagePath)) { $imageObj = new Varien_Image($imagePath); $imageObj->constrainOnly(true); $imageObj->keepAspectRatio(true); $imageObj->keepFrame(true); $imageObj->keepTransparency(true); $imageObj->backgroundColor($this->getBackgroundColor()); $imageObj->resize($width, $height); $imageObj->save($imageResized); } $imageUrl = Mage::getBaseUrl('media') . "catalog/category/resized/" . $imageName; return $imageUrl; }
public function getCategoryImage($category = null, $width = 300, $height = 300, $image_type = "thumbnail") { if (empty($category) && !is_object($category)) { return ""; } if ($image_type == "thumbnail") { $_file_name = $category->getThumbnail(); } else { $_file_name = $category->getImage(); } $_media_dir = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category' . DS; $cache_dir = $_media_dir . 'cache' . DS; if ($_file_name) { if (file_exists($cache_dir . $_file_name)) { return Mage::getBaseUrl('media') . '/catalog/category/cache/' . $_file_name; } elseif (file_exists($_media_dir . $_file_name)) { if (!is_dir($cache_dir)) { mkdir($cache_dir); } $_image = new Varien_Image($_media_dir . $_file_name); $_image->constrainOnly(true); $_image->keepAspectRatio(true); $_image->keepTransparency(true); $_image->resize((int) $width, (int) $height); $_image->save($cache_dir . $_file_name); return Mage::getBaseUrl('media') . '/catalog/category/cache/' . $_file_name; } } return ""; }
public function resizeImage($image, $type = "l", $width, $height, $storeid = null) { $image = str_replace("/", DS, $image); $_imageUrl = Mage::getBaseDir('media') . DS . $image; if ($storeid === null) { $storeid = Mage::app()->getStore()->getId(); } if (!$storeid) { $imageResized = Mage::getBaseDir('media') . DS . "resized" . DS . $type . DS . $image; } else { $image2 = str_replace("blog" . DS, "", $image); $image = "blog" . DS . $storeid . DS . $image2; $imageResized = Mage::getBaseDir('media') . DS . "resized" . DS . $type . DS . "blog" . DS . $storeid . DS . $image2; } if (!file_exists($imageResized) && file_exists($_imageUrl)) { $imageObj = new Varien_Image($_imageUrl); $imageObj->quality(100); $imageObj->constrainOnly(true); $imageObj->keepAspectRatio(false); $imageObj->keepFrame(false); $imageObj->keepTransparency(true); $imageObj->resize($width, $height); $imageObj->save($imageResized); } return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'resized/' . "{$type}/" . str_replace(DS, "/", $image); }
public function resizeImg($fileName, $width, $height = null) { $baseURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); $imageURL = $baseURL . '/' . 'magiccart/blog' . '/' . $fileName; $basePath = Mage::getBaseDir('media'); $imagePath = $basePath . DS . 'magiccart/blog/' . str_replace('/', DS, $fileName); $extra = $width . 'x' . $height; $newPath = Mage::getBaseDir('media') . DS . 'magiccart/blog' . DS . "cache" . DS . $extra . '/' . str_replace('/', DS, $fileName); //if width empty then return original size image's URL if ($width != '' && $height != '') { //if image has already cache then just return URL if (file_exists($imagePath) && is_file($imagePath) && !file_exists($newPath)) { $imageObj = new Varien_Image($imagePath); $imageObj->constrainOnly(TRUE); $imageObj->keepAspectRatio(FALSE); $imageObj->keepTransparency(true); $imageObj->keepFrame(FALSE); $imageObj->quality(100); //$width, $height - sizes you need (Note: when keepAspectRatio(TRUE), height would be ignored) $imageObj->resize($width, $height); $imageObj->save($newPath); } $cacheURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . "magiccart/blog" . '/' . "cache" . '/' . $extra . '/' . $fileName; } else { $cacheURL = $imageURL; } return $cacheURL; }
public function getLableImage($fileName) { //$fileName = Mage::getStoreConfig('productlable/sample/newimage'); $width = 50; $height = 50; $folderURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); $imageURL = $folderURL . $fileName; $basePath = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . 'theme' . DS . $fileName; $newPath = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . "resized" . DS . $fileName; //if width empty then return original size image's URL if ($width != '') { //if image has already resized then just return URL if (file_exists($basePath) && is_file($basePath) && !file_exists($newPath)) { $imageObj = new Varien_Image($basePath); $imageObj->constrainOnly(TRUE); $imageObj->keepAspectRatio(FALSE); $imageObj->keepFrame(FALSE); $imageObj->keepTransparency(TRUE); $imageObj->resize($width, $height); $imageObj->save($newPath); } $resizedURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . "resized/" . $fileName; } else { $resizedURL = $imageURL; } return $resizedURL; }
public function resize($width, $height) { if (!($imageUrl = $this->getImageUrl())) { return ''; } $dir = Mage::getBaseDir('media') . DS . "testimonials" . DS . "pictures" . DS . "resized"; if (!file_exists($dir)) { mkdir($dir, 0777); } $imageName = substr(strrchr($imageUrl, "/"), 1); $imageName = $width . '_' . $height . '_' . $imageName; $imageResized = $dir . DS . $imageName; $imagePath = str_replace(Mage::getBaseUrl('media'), 'media/', $imageUrl); $imagePath = Mage::getBaseDir() . DS . str_replace("/", DS, $imagePath); if (!file_exists($imageResized) && file_exists($imagePath)) { $imageObj = new Varien_Image($imagePath); $imageObj->constrainOnly(true); $imageObj->keepAspectRatio(true); $imageObj->keepFrame(false); $imageObj->keepTransparency(true); $imageObj->resize($width, $height); $imageObj->save($imageResized); } $imageUrl = Mage::getBaseUrl('media') . "testimonials/pictures/resized/" . $imageName; return $imageUrl; }
public function getResizedUrl($imgUrl, $x, $y = NULL) { $imgPath = $this->splitImageValue($imgUrl, "path"); $imgName = $this->splitImageValue($imgUrl, "name"); /** * Path with Directory Seperator */ $imgPath = str_replace("/", DS, $imgPath); /** * Absolute full path of Image */ $imgPathFull = Mage::getBaseDir("media") . DS . $imgPath . DS . $imgName; /** * If Y is not set set it to as X */ $widht = $x; $y ? $height = $y : ($height = $x); /** * * Resize folder is widthXheight */ $resizeFolder = $widht . "X" . $height; /** * Image resized path will then be */ $imageResizedPath = Mage::getBaseDir("media") . DS . $imgPath . DS . $resizeFolder . DS . $imgName; /** * First check in cache i.e image resized path * If not in cache then create image of the width=X and height = Y */ if (!file_exists($imageResizedPath) && file_exists($imgPathFull)) { $imageObj = new Varien_Image($imgPathFull); $imageObj->constrainOnly(true); // image picture will not be bigger, than it was $imageObj->keepAspectRatio(true); // image picture width/height will not be distorted $imageObj->keepFrame(true); // image will have dimensions, set in $width/$height $imageObj->keepTransparency(true); $imageObj->backgroundColor(array(255, 255, 255)); $imageObj->resize($widht, $height); $imageObj->save($imageResizedPath); } /** * Else image is in cache replace the Image Path with / for http path. */ $imgUrl = str_replace(DS, "/", $imgPath); /** * Return full http path of the image */ return Mage::getBaseUrl("media") . $imgUrl . "/" . $resizeFolder . "/" . $imgName; }
/** * if there's no thumb for the image, we make it * * @param string $imageName * @param int $size * * @return string */ public function resize($imageName, $size) { $helper = Mage::helper('adjicon'); $fileName = $helper->getThumbnailFileName($size, $imageName); if (!file_exists($this->_imagePath . $fileName)) { $image = new Varien_Image($this->_imagePath . $imageName); $image->keepFrame(true); $image->keepAspectRatio(true); $image->keepTransparency(true); $image->backgroundColor(array(255, 255, 255)); $image->resize($size); $image->save(null, $fileName); } return $fileName; }
function getImage($src, $xSize = 150, $ySize = 150, $keepRatio = true, $styles = "") { if ($src != "") { $image = new Varien_Image(Mage::getBaseDir('media') . DS . $src); $image->constrainOnly(false); $image->keepAspectRatio($keepRatio); $image->setImageBackgroundColor(0xffffff); $image->keepTransparency(true); $image->resize($xSize, $ySize); $image->save(Mage::getBaseDir('media') . DS . 'stores/cache/' . basename($src)); return "<img style='" . $styles . "' src='" . Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'stores/cache/' . basename($src) . "'/>"; } else { return; } }
public function getResizedUrl($imgName, $x, $y = NULL) { $imgPathFull = Mage::getBaseDir("media") . DS . $imgName; $widht = $x; $y ? $height = $y : ($height = $x); $resizeFolder = "j2t_resized"; $imageResizedPath = Mage::getBaseDir("media") . DS . $resizeFolder . DS . $imgName; if (!file_exists($imageResizedPath) && file_exists($imgPathFull)) { $imageObj = new Varien_Image($imgPathFull); $imageObj->constrainOnly(true); $imageObj->keepAspectRatio(true); $imageObj->keepTransparency(true); $imageObj->resize($widht, $height); $imageObj->save($imageResizedPath); } return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . $resizeFolder . DS . $imgName; }
public function resize($image, $width, $height) { $image = str_replace("/", DS, $image); $_imageUrl = Mage::getBaseDir('media') . DS . $image; $imageResized = Mage::getBaseDir('media') . DS . "resized" . DS . "{$width}x{$height}" . DS . $image; if (!file_exists($imageResized) && file_exists($_imageUrl)) { $imageObj = new Varien_Image($_imageUrl); $imageObj->quality(100); $imageObj->constrainOnly(true); $imageObj->keepAspectRatio(true); $imageObj->keepFrame(false); $imageObj->keepTransparency(true); $imageObj->resize($width, $height); $imageObj->save($imageResized); } return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'resized/' . "{$width}x{$height}/" . str_replace(DS, "/", $image); }
public function resize($width = 100, $height = null) { $height = $height ? $height : $width; $this->createCacheFolder($width, $height); $orgFolder = $this->getOrgFolder(); $cacheSizeFolder = $this->getCacheSizeFolder($width, $height); $imageFile = $this->_cat->getImage(); if (!file_exists($cacheSizeFolder . DS . $imageFile)) { if (file_exists($orgFolder . DS . $imageFile)) { $fileImg = new Varien_Image($orgFolder . DS . $imageFile); $fileImg->keepAspectRatio(true); $fileImg->keepFrame(true); $fileImg->keepTransparency(true); $fileImg->constrainOnly(false); $fileImg->backgroundColor(array(255, 255, 255)); $fileImg->resize($width, $height); $fileImg->save($cacheSizeFolder . DS . $imageFile, null); } } return Mage::getBaseUrl('media') . 'catalog/category/cache/' . $this->_cat->getId() . '/' . $width . 'x' . $height . '/' . $imageFile; }
public function resizeImage($image, $width, $height) { $image = str_replace("/", DS, $image); $_imageUrl = Mage::getBaseDir('media') . DS . $image; $imageResized = Mage::getBaseDir('media') . DS . "resized" . DS . "{$width}x{$height}" . DS . $image; $quality = $this->getConfig("resize_quality"); if (!file_exists($imageResized) && file_exists($_imageUrl)) { $imageObj = new Varien_Image($_imageUrl); $imageObj->quality(100); $imageObj->constrainOnly(true); $imageObj->keepAspectRatio(true); $imageObj->keepFrame(false); $imageObj->keepTransparency(true); $imageObj->resize($width, $height); if ($quality) { $imageObj->quality($quality); } $imageObj->save($imageResized); } return 'resized/' . "{$width}x{$height}/" . str_replace(DS, "/", $image); }
public function resizeImage($imageName, $width = NULL, $height = NULL, $imagePath = NULL, $type) { $imagePath = str_replace("/", DS, $imagePath); $imagePathFull = Mage::getBaseDir('media') . DS . $imagePath . DS . $imageName; if ($width == NULL && $height == NULL) { $width = 100; $height = 100; } $resizePath = $width . 'x' . $height; $resizePathFull = Mage::getBaseDir('media') . DS . $imagePath . DS . $type . DS . $resizePath . DS . $imageName; if (file_exists($imagePathFull) && !file_exists($resizePathFull)) { $imageObj = new Varien_Image($imagePathFull); $imageObj->keepTransparency(true); //$imageObj->constrainOnly(TRUE); $imageObj->keepAspectRatio(TRUE); $imageObj->resize($width, $height); $imageObj->save($resizePathFull); } $imagePath = str_replace(DS, "/", $imagePath); return Mage::getBaseUrl("media") . $imagePath . "/" . $type . "/" . $resizePath . "/" . $imageName; }
public function resizeImage($imageName, $width = NULL, $height = NULL, $imagePath = 'colorswatch/image') { $imagePath = str_replace("/", DS, $imagePath); $imagePathFull = Mage::getBaseDir('media') . DS . $imagePath . DS . $this->getCurrentImageType() . DS . $this->getColorSwatch()->getAttributeId() . DS . $this->getColorSwatch()->getOptionId() . DS . $imageName; if ($width == NULL && $height == NULL) { $width = 100; $height = 100; } $resizePath = $width . 'x' . $height; $resizePathFull = Mage::getBaseDir('media') . DS . $imagePath . DS . $this->getCurrentImageType() . DS . $this->getColorSwatch()->getAttributeId() . DS . $this->getColorSwatch()->getOptionId() . DS . $resizePath . DS . $imageName; if (file_exists($imagePathFull) && is_file($imagePathFull) && !file_exists($resizePathFull)) { $imageObj = new Varien_Image($imagePathFull); $imageObj->constrainOnly(TRUE); $imageObj->keepAspectRatio(TRUE); $imageObj->keepFrame(FALSE); $imageObj->keepTransparency(TRUE); $imageObj->resize($width, $height); $imageObj->save($resizePathFull); } $imagePath = str_replace(DS, "/", $imagePath); return Mage::getBaseUrl("media") . $imagePath . "/" . $this->getCurrentImageType() . '/' . $this->getColorSwatch()->getAttributeId() . '/' . $this->getColorSwatch()->getOptionId() . '/' . $resizePath . "/" . $imageName; }
/** * Run script * */ public function run() { if (!$this->getArg('d')) { echo $this->usageHelp(); return; } /** @var $iterator SplFileObject[] */ $iterator = new DirectoryIterator($this->getArg('d')); $start = microtime(true); $i = 0; $max = 0; do { foreach ($iterator as $file) { if (!$file->isDir()) { $image = new Varien_Image($this->getArg('d') . DS . $file->getFilename(), Varien_Image_Adapter::ADAPTER_IM); $image->keepFrame(true); $image->keepAspectRatio(true); $image->keepTransparency(true); $image->backgroundColor(array(255, 255, 255)); $image->resize(186, 500); $image->setWatermarkImageOpacity(30); $image->setWatermarkPosition(Varien_Image_Adapter_Abstract::POSITION_TOP_LEFT); $image->setWatermarkHeigth(100); $image->setWatermarkWidth(100); $image->quality(80); $watermark = $this->getArg('d') . DS . 'watermark' . DS . 'watermark.png'; if (is_readable($watermark)) { $image->watermark($watermark); } $image->save($this->getArg('d') . DS . 'result', $file->getFilename()); } } } while ($i++ < $max); $endMem = memory_get_usage(true); $end = microtime(true); echo "Duration in seconds: " . ($end - $start) . PHP_EOL; echo "Memory usage in MB: " . $endMem / 1024 / 1024 . PHP_EOL; }
public function resizeImage($image, $width = 100, $height = 100, $qualtity = 100) { if ($width == 0 || $height == 0) { return Mage::getBaseUrl("media") . $image; } $media_base_url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); $image = str_replace($media_base_url, "", $image); $media_base_url = str_replace("https://", "http://", $media_base_url); $image = str_replace($media_base_url, "", $image); $_imageUrl = Mage::getBaseDir('media') . DS . $image; $_imageResized = Mage::getBaseDir('media') . DS . "resized" . DS . (int) $width . "x" . (int) $height . DS . $image; if (!file_exists($_imageResized) && file_exists($_imageUrl)) { $imageObj = new Varien_Image($_imageUrl); $imageObj->quality($qualtity); $imageObj->constrainOnly(TRUE); $imageObj->keepAspectRatio(TRUE); $imageObj->keepTransparency(true); $imageObj->keepFrame(FALSE); $imageObj->resize($width, $height); $imageObj->save($_imageResized); } return Mage::getBaseUrl("media") . "resized/" . (int) $width . "x" . (int) $height . "/" . $image; }
public function resizeImage($image, $width, $height) { $image = str_replace("ves_layerslider/upload/", "", $image); $image = str_replace("/", DS, $image); $_imageUrl = Mage::helper("ves_layerslider")->getImageBaseDir() . $image; $imageResized = Mage::getBaseDir('media') . DS . "resized" . DS . "{$width}x{$height}" . DS . $image; $quality = $this->getConfig("resize_quality"); if (!file_exists($imageResized) && file_exists($_imageUrl)) { $imageObj = new Varien_Image($_imageUrl); if ($quality) { $imageObj->quality($quality); } else { $imageObj->quality(100); } $imageObj = new Varien_Image($_imageUrl); $imageObj->constrainOnly(true); $imageObj->keepAspectRatio(true); $imageObj->keepFrame(false); $imageObj->keepTransparency(true); $imageObj->resize($width, $height); $imageObj->save($imageResized); } return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'resized/' . "{$width}x{$height}/" . str_replace(DS, "/", $image); }
/** * Retrieve custom size image url * * * @param string $imageUrl * @param int $width * @param int $height * @return string|null */ public function getCustomSizeImageUrl($imageUrl, $width = 100, $height = 100) { $screenSize = $width . 'x' . $height; $customDir = $this->getMediaPath('custom' . DS . $screenSize); $this->_verifyDirExist($customDir); $imageUrl = explode('/', $imageUrl); $file = array_pop($imageUrl); $filePath = Mage_XmlConnect_Model_Images::getBasePath() . DS . $file; if (!file_exists($customDir . DS . $file)) { $image = new Varien_Image($filePath); $widthOriginal = $image->getOriginalWidth(); $heightOriginal = $image->getOriginalHeight(); if ($width != $widthOriginal) { $widthOriginal = $width; } if ($height != $heightOriginal) { $heightOriginal = $height; } if ($widthOriginal != $image->getOriginalWidth() || $heightOriginal != $image->getOriginalHeight()) { $image->keepTransparency(true); $image->keepFrame(true); $image->keepAspectRatio(true); $image->backgroundColor(array(255, 255, 255)); $image->resize($widthOriginal, $heightOriginal); $image->save($customDir, basename($file)); } } return $this->getMediaUrl("custom/{$screenSize}/" . basename($file)); }
/** * Retrieve custom size image url * * @param string $imageFile * @param int $width * @param int $height * @return string|bool */ public function getCustomSizeImageUrl($imageFile, $width = 100, $height = 100) { /** @var $imageHelper Mage_XmlConnect_Helper_Image */ $imageHelper = Mage::helper('xmlconnect/image'); $screenSize = $width . 'x' . $height; $customDir = $imageHelper->getMediaPath('custom' . DS . $screenSize); $ioFile = new Varien_Io_File(); $ioFile->checkAndCreateFolder($customDir); $filePath = self::getBasePath() . DS . $imageFile; $isImagePng = true; if (!$ioFile->fileExists($filePath)) { return false; } $originalImageType = $this->_getImageType($filePath); if ($originalImageType !== IMAGETYPE_PNG) { $imageFile = $this->_convertFileExtensionToPng($imageFile); $isImagePng = false; } $customSizeFile = $customDir . DS . $imageFile; if (!file_exists($customSizeFile)) { if (!$isImagePng) { $filePath = $this->_forcedConvertPng($filePath, $customSizeFile, $originalImageType); } $image = new Varien_Image($filePath); $widthOriginal = $image->getOriginalWidth(); $heightOriginal = $image->getOriginalHeight(); if ($width != $widthOriginal) { $widthOriginal = $width; } if ($height != $heightOriginal) { $heightOriginal = $height; } if ($widthOriginal != $image->getOriginalWidth() || $heightOriginal != $image->getOriginalHeight()) { $image->keepTransparency(true); $image->keepFrame(true); $image->keepAspectRatio(true); $image->backgroundColor(array(0, 0, 0)); $image->resize($widthOriginal, $heightOriginal); $image->save($customDir, basename($imageFile)); } else { $ioFile->cp($filePath, $customSizeFile); } } return $imageHelper->getMediaUrl("custom/{$screenSize}/" . basename($imageFile)); }
public function getSmallImageFile($fileOrig, $smallPath, $newFileName) { try { $image = new Varien_Image($fileOrig); $origHeight = $image->getOriginalHeight(); $origWidth = $image->getOriginalWidth(); // settings $image->keepAspectRatio(true); $image->keepFrame(true); $image->keepTransparency(true); $image->constrainOnly(false); $image->backgroundColor(array(255, 255, 255)); $image->quality(90); $width = null; $height = null; if (Mage::app()->getStore()->isAdmin()) { if ($origHeight > $origWidth) { $height = $this->getImagesThumbnailsSize(); } else { $width = $this->getImagesThumbnailsSize(); } } else { $configWidth = $this->getImagesThumbnailsSize(); $configHeight = $this->getImagesThumbnailsSize(); if ($origHeight > $origWidth) { $height = $configHeight; } else { $width = $configWidth; } } $image->resize($width, $height); $image->constrainOnly(true); $image->keepAspectRatio(true); $image->keepFrame(false); //$image->display(); $image->save($smallPath, $newFileName); } catch (Exception $e) { } }
public function _resizeImage($image, $config = array(), $type = "product", $folder = 'resized') { if ((int) $config['function'] == 0 || $config['width'] <= 0) { return $image; } $_file_name = substr(strrchr($image, "/"), 1); $_media_dir = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . 'catalog' . DS . $type . DS; $cache_dir = $_media_dir . $folder . DS . $config['width'] . 'x' . $config['height'] . DS . md5(serialize($config)); $dirImg = Mage::getBaseDir() . str_replace("/", DS, strstr($image, '/media')); $from_skin_nophoto = Mage::getBaseDir() . str_replace("/", DS, strstr($image, '/skin')); $dirImg = strpos($dirImg, 'media') !== false ? $dirImg : ''; $dirImg = strpos($from_skin_nophoto, 'skin') !== false && $dirImg == '' ? $from_skin_nophoto : $dirImg; $new_image = ''; if (file_exists($cache_dir . DS . $_file_name) && @getimagesize($cache_dir . DS . $_file_name) !== false) { $new_image = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/' . $type . '/' . $folder . '/' . $config['width'] . 'x' . $config['height'] . '/' . md5(serialize($config)) . '/' . $_file_name; } elseif (file_exists($dirImg) && $dirImg != '') { if (!is_dir($cache_dir)) { @mkdir($cache_dir, 0777); } $height = $config['height'] == '' ? null : $config['height']; $hex = $config['background']; $rgbColor = $this->HexToRGB($hex); $image = new Varien_Image($dirImg); $image->constrainOnly($config['constrainOnly']); $image->keepFrame($config['keepFrame']); $image->keepTransparency($config['keepTransparency']); $image->keepAspectRatio($config['keepAspectRatio']); $image->backgroundColor($rgbColor); $image->resize($config['width'], $height); $image->save($cache_dir . DS . $_file_name); $new_image = Mage::getBaseUrl('media') . 'catalog/' . $type . '/' . $folder . '/' . $config['width'] . 'x' . $config['height'] . '/' . md5(serialize($config)) . '/' . $_file_name; } else { return $image; } return $new_image; }
public function getResizedImage($width = null, $height = null, $quality = 100, $image = NULL) { if (!$image) { return false; } $imageUrl = Mage::getBaseDir('media') . DS . "catalog" . DS . "category" . DS . $image; if (!is_file($imageUrl)) { return false; } $imageResized = Mage::getBaseDir('media') . DS . "catalog" . DS . "category" . DS . "cat_resized" . DS . $image; if (!file_exists($imageResized) && file_exists($imageUrl) || file_exists($imageUrl) && filemtime($imageUrl) > filemtime($imageResized)) { $imageObj = new Varien_Image($imageUrl); $imageObj->constrainOnly(TRUE); $imageObj->keepAspectRatio(FALSE); $imageObj->keepFrame(FALSE); $imageObj->quality(100); $imageObj->keepTransparency(true); $imageObj->resize($width, $height); $imageObj->save($imageResized); } if (file_exists($imageResized)) { return Mage::getBaseUrl('media') . "catalog/category/cat_resized/" . $image; } else { return $imageUrl; } }