`
yanggaojiao
  • 浏览: 80144 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Magento image 操作

PHP 
阅读更多

由于lib/Varien/Image.php  的 Varient_Image类定义并实现了很多对操作image用的方法。所以我们在magento中操作Image将变得非常简易. 下面是一个该类应用的简单例子:

$fileName = 'skin\frontend\default\default\images\media\col_left_callout.jpg';
$watermarkName = 'skin\frontend\default\default\images\media\best_selling_img01.jpg';
 
$image = new Varien_Image($fileName);
 
// this function accepts integer, hexadecimal format is more convenient for me
$image->setImageBackgroundColor(0xFFFFFF);
 
// let's add another image with 15% opacity, last parameter makes the image to be repeated 
$image->watermark($watermarkName, 0, 0, 15, true);
 
$image->resize(250);
 
$image->rotate(45);
 
// this will generate proper headers for transformed image so don't use this method if you plan to display any other content
$image->display();
 
// Magento will attempt to create missing directories
$image->save('media/myimages/myTransformedImage.jpg');

 

 

更多应用请前往lib/Varien/Image.php ,该类提供了更多useful的方法。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics