由于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的方法。