本文整理汇总了PHP中Varien_Image::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Image::save方法的具体用法?PHP Varien_Image::save怎么用?PHP Varien_Image::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Image
的用法示例。
在下文中一共展示了Varien_Image::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resizeImg
public function resizeImg($fileName, $width, $height = '')
{
$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 . "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(TRUE);
$imageObj->keepFrame(TRUE);
$imageObj->backgroundColor(array(255, 255, 255));
// white background!
$imageObj->resize($width, $height);
$imageObj->save($newPath);
}
$resizedURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . "resized" . DS . $fileName;
} else {
$resizedURL = $imageURL;
}
return $resizedURL;
}
示例2: resizeCategoryImage
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;
}
示例3: createPreview
public function createPreview($name, $pathModule, $id, $width, $height)
{
if (isset($_FILES[$name]['name']) && $_FILES[$name]['name'] != null) {
$path = Mage::getBaseDir('media') . DS . $pathModule . DS;
$imageObj = new Varien_Image($path . '/' . $_FILES[$name]['name']);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(FALSE);
$imageObj->keepFrame(FALSE);
$currentRatio = $imageObj->getOriginalWidth() / $imageObj->getOriginalHeight();
$targetRatio = $width / $height;
if ($targetRatio > $currentRatio) {
$imageObj->resize($width, null);
} else {
$imageObj->resize(null, $height);
}
$diffWidth = $imageObj->getOriginalWidth() - $width;
$diffHeight = $imageObj->getOriginalHeight() - $height;
//$imageObj->resize($width, $height);
$imageObj->crop(floor($diffHeight * 0.5), floor($diffWidth / 2), ceil($diffWidth / 2), ceil($diffHeight * 0.5));
if (empty($id)) {
$id = Mage::getModel('evoqueflex/evoqueflex')->getCollection()->addOrder('slide_id', 'ASC')->getLastItem()->toArray();
$id = $id['slide_id'];
}
$userfile_extn = explode(".", strtolower($_FILES[$name]['name']));
$imageObj->save($path . 'preview_' . $id . '.' . $userfile_extn[1]);
}
}
示例4: resizeImg
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;
}
示例5: resize
/**
* Resize image method
*
* @param $fileName string
* @param $width int
* @param $height null|int
* @return string
*/
public function resize($fileName, $width, $height = null)
{
$heightPath = is_null($height) ? 0 : $height;
$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 . "slider" . DS . "resized" . DS . $width . DS . $heightPath . 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->resize($width, $height);
$imageObj->save($newPath);
}
$resizedURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . "slider" . DS . "resized" . DS . $width . DS . $heightPath . DS . $fileName;
} else {
$resizedURL = $imageURL;
}
// Windows DS fix
if (DS == '\\') {
$resizedURL = str_replace('\\', '/', $resizedURL);
}
return $resizedURL;
}
示例6: _entityImageUrl
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);
}
示例7: getPostImage
public function getPostImage($width = false, $height = false)
{
$img = $this->getData('post_image');
if (empty($img)) {
return false;
}
$imgDir = dirname($img);
$imgFile = basename($img);
if (!$width) {
return $img;
}
//if(!$height) $height = $width;
$imageUrl = Mage::getBaseDir('media') . DS . $img;
if (!is_file($imageUrl)) {
return false;
}
$imageResized = Mage::getBaseDir('media') . DS . $imgDir . "/resized/" . $width . "x" . $height . DS . $imgFile;
if (file_exists($imageResized)) {
return $imgDir . "/resized/" . $width . "x" . $height . DS . $imgFile;
}
$imageObj = new Varien_Image($imageUrl);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(TRUE);
$imageObj->keepFrame(FALSE);
$imageObj->quality(100);
$imageObj->resize($width, $height);
$imageObj->save($imageResized);
return $imgDir . "/resized/" . $width . "x" . $height . DS . $imgFile;
}
示例8: getCatResizedImage
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();
}
}
示例9: resizeImg
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;
}
示例10: getRetouchedResizedImage
public function getRetouchedResizedImage($image, $x, $y)
{
if (!$image || !$x || !$y) {
return false;
}
$imageUrl = Mage::getBaseDir('media') . DS . "surgery" . DS . "retouched" . DS . $image;
if (!is_file($imageUrl)) {
return false;
}
$imageResized = Mage::getBaseDir('media') . DS . "surgery" . DS . "retouched" . DS . "resized" . DS . $image;
if (file_exists($imageResized)) {
return Mage::getBaseUrl('media') . "surgery" . DS . "retouched" . DS . "resized" . DS . $image;
}
if (!file_exists($imageResized) && file_exists($imageUrl)) {
try {
$imageObj = new Varien_Image($imageUrl);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(TRUE);
$imageObj->keepFrame(FALSE);
$imageObj->quality(100);
$imageObj->resize($x, $y);
$imageObj->save($imageResized);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}
return Mage::getBaseUrl('media') . "surgery" . DS . "retouched" . DS . "resized" . DS . $image;
}
示例11: injectImage
/**
* 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;
}
示例12: _resizeSwatchImage
/**
* Performs the resize operation on the given swatch image file and returns a
* relative path to the resulting image file
*
* @param string $filename
* @param string $tag
* @param int $width
* @param int $height
* @return string
*/
protected function _resizeSwatchImage($filename, $tag, $width, $height)
{
if (!Mage::helper('uaudio_storage')->isEnabled()) {
return parent::_resizeSwatchImage($filename, $tag, $width, $height);
}
// Form full path to where we want to cache resized version
$destPathArr = array(self::SWATCH_CACHE_DIR, Mage::app()->getStore()->getId(), $width . 'x' . $height, $tag, trim($filename, '/'));
$destPath = implode('/', $destPathArr);
$storageModel = Mage::getSingleton('core/file_storage')->getStorageModel();
// Check if cached image exists already
$fullDest = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . $destPath;
if (!$storageModel->fileExists($fullDest)) {
// Check for source image
if ($tag == 'product') {
$sourceFilePath = Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath() . $filename;
} else {
$sourceFilePath = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . self::SWATCH_FALLBACK_MEDIA_DIR . DS . $filename;
}
if (!$storageModel->fileExists($sourceFilePath)) {
return false;
}
// Do resize and save
$tmpFile = $storageModel->copyFiletoTmp($sourceFilePath);
$processor = new Varien_Image($tmpFile);
$processor->resize($width, $height);
$processor->save($tmpFile);
$storageModel->moveFile($tmpFile, $fullDest);
}
return $destPath;
}
示例13: getProperDimensionsPictureUrl
public function getProperDimensionsPictureUrl($yahooId, $pictureUrl)
{
$pictureUrl = str_replace('_normal', '', $pictureUrl);
$url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'le' . '/' . 'sociallogin' . '/' . 'yahoo' . '/' . $yahooId;
$filename = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . 'le' . DS . 'sociallogin' . DS . 'yahoo' . DS . $yahooId;
$directory = dirname($filename);
if (!file_exists($directory) || !is_dir($directory)) {
if (!@mkdir($directory, 0777, true)) {
return null;
}
}
if (!file_exists($filename) || file_exists($filename) && time() - filemtime($filename) >= 3600) {
$client = new Zend_Http_Client($pictureUrl);
$client->setStream();
$response = $client->request('GET');
stream_copy_to_stream($response->getStream(), fopen($filename, 'w'));
$imageObj = new Varien_Image($filename);
$imageObj->constrainOnly(true);
$imageObj->keepAspectRatio(true);
$imageObj->keepFrame(false);
$imageObj->resize(150, 150);
$imageObj->save($filename);
}
return $url;
}
示例14: getProfileImage
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;
}
示例15: resizeImg
/**
* 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;
}