本文整理汇总了PHP中Varien_Image::quality方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Image::quality方法的具体用法?PHP Varien_Image::quality怎么用?PHP Varien_Image::quality使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Image
的用法示例。
在下文中一共展示了Varien_Image::quality方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: resizeImage
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);
}
示例7: resizeImage
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);
}
示例8: resize
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);
}
示例9: _getResizedImage
protected function _getResizedImage($file, $width, $height, $resizeMode = 'cover')
{
if (empty($file)) {
return false;
}
$width = (int) $width;
$height = (int) $height;
$imagePath = $this->getImageFullPath($file);
$imageFileResized = $width . '_' . $height . '_' . $resizeMode . DS . $file;
$imageFileResizedFullPath = $this->getImageCacheFullPath($imageFileResized);
if (!file_exists($imageFileResizedFullPath) && file_exists($imagePath) || file_exists($imagePath) && filemtime($imagePath) > filemtime($imageFileResizedFullPath)) {
$finalAspectRatio = $width / $height;
$imageObj = new Varien_Image($imagePath);
$imageObj->backgroundColor(array(255, 255, 255));
$originalWidth = (int) $imageObj->getOriginalWidth();
$originalHeight = (int) $imageObj->getOriginalHeight();
$originalAspectRatio = $originalWidth / $originalHeight;
if ($resizeMode == 'cover') {
if ($originalAspectRatio > $finalAspectRatio) {
$cropWidth = $finalAspectRatio * $originalHeight;
$widthDiff = $originalWidth - $cropWidth;
$cropX = (int) ($widthDiff / 2);
$imageObj->crop(0, $cropX, $cropX, 0);
} else {
$cropHeight = (int) ($originalWidth / $finalAspectRatio);
$heightDiff = $originalHeight - $cropHeight;
$cropY = (int) ($heightDiff / 2);
$imageObj->crop($cropY, 0, 0, $cropY);
}
} else {
$imageObj->constrainOnly(false);
$imageObj->keepAspectRatio(true);
$imageObj->keepFrame(true);
}
$imageObj->resize($width, $height);
$imageObj->quality(100);
$imageObj->save($imageFileResizedFullPath);
}
$imageCacheUrl = $this->getImageCacheUrl($imageFileResized);
if (file_exists($imageFileResizedFullPath)) {
return $imageCacheUrl;
}
return false;
}
示例10: resizeImage
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);
}
示例11: run
/**
* 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;
}
示例12: resizeImage
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;
}
示例13: getSmallImageFile
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) {
}
}
示例14: getResizedImage
public function getResizedImage($image, $width = null, $height = null, $quality = 100)
{
$imageUrl = Mage::getBaseDir('media') . DS . "catalog" . DS . "category" . DS . $image;
if (!is_file($imageUrl)) {
return false;
}
$imageResized = Mage::getBaseDir('media') . DS . "catalog" . DS . "product" . DS . "cache" . 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 ( true );
$imageObj->keepFrame(false);
$imageObj->quality($quality);
if ($width) {
$imageObj->resize($width, $height ? $height : null);
}
$imageObj->save($imageResized);
}
if (file_exists($imageResized)) {
return $image;
} else {
return false;
}
}
示例15: getResizedImage
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;
}
}