16
Aug
Image manipulation in Magento is quite easy thanks to Varien_Image class defined in lib/Varien/Image.php file. Here’s a self-explained example of basic usage of this class:
$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');


