Magento Wraps PHP Image Library Functions in its library with its own wrapper functions. Magento Provides the general adapter for image manipulation. This gives us the flexibility to use any PHP libraries like GD2, imagemagik etc.

Some of the common wrapper functions are

  • crop
  • resize
  • rotate


You can make use of these functions in your custom code. To Utilise these functions we need to create an object of type Varien_Image with image name along with the path.

Crop:

To Crop a Particular Image call the crop function with top,left,right,bottom coordinates

PHP Code:
 $image = new Varien_Image($path);
 
$image->crop(10,10,10,10); //top , left, right,bottom coordinates 
Rotate:


$image = new Varien_Image($path);
$image->rotate(30); // Angle to rotate

Example Code Snippet:


PHP Code:
$image = new Varien_Image($path$imageName);
// Create an object of type Varien_Image

$image->constrainOnly(TRUE);
// Image Constraint
$image->keepAspectRatio(TRUE);

$image->resize(300,300);
// resize function with desired width,height

image->save($path.$imageName);
// Save Image in the given path 

View more threads in the same category: