Magento: Crop image

Here is a quick tip to crop image to any degree of your choice in Magento. The crop function of Varien_Image does the magic :) Here goes the code: $mainImage = Mage::getBaseDir('media') . DS . 'test' . DS . 'image.jpg'; $image = new Varien_Image($mainImage); // crop image // crop($top=0, $left=0, $right=0, $bottom=0) $image->crop(10, 10, 10, … Read more

Magento: Rotate image

Here is a quick tip to rotate image to any degree of your choice in Magento. The rotate function of Varien_Image does the magic :) Here goes the code: $mainImage = Mage::getBaseDir('media') . DS . 'test' . DS . 'image.jpg'; $image = new Varien_Image($mainImage); // rotate image with the angle of your choice // rotate($angle) … Read more

Magento: Admin Controller Override

I had to override adminhtml controller class (Mage_Adminhtml_System_ConfigController) with my module’s controller class (MyNamespace_MyModule_ConfigController). It was really tough to find the right solution. I googled, searched in magentocommerce forum and found a lot of solutions. But they didn’t work for me. After searching & trying more, I got some work done with the following piece … Read more

Magento: Create Watermark Image

It’s very very easy to create watermark image with Magento code. The Varien_Image class does the magic. The function watermark creates watermark on the image. Here is the code: $mainImage = Mage::getBaseDir('media') . DS . 'test' . DS . 'image.jpg'; $watermarkImage = Mage::getBaseDir('media') . DS . 'test' . DS . 'watermark.jpg'; $image = new Varien_Image($mainImage); … Read more

Magento: Easily add breadcrumbs to any page

Breadcrumbs are very useful for user navigation. Breadcrumbs for product page, category page, etc. are created by default Magento code. The following code will show breadcrumbs created by Magento. You can print the following code anywhere in php or phtml files. echo $this->getLayout()->getBlock('breadcrumbs')->toHtml(); You can create you own breadcrumbs as well. Like, you may need … Read more

Magento: How to upload file?

In adminhtml, you might have the following code in any form. Here ‘logo‘ is the name of the input type file. Or, you may have any HTML Form with the File field in the frontend page. Remember that your form’s enctype should be multipart/form-data. $fieldset->addField('logo', 'file', array( 'label' => 'Small Logo', 'required' => false, 'name' … Read more

Magento: How to set and get registry?

Registry means registering or creating a new variable which is to be used later on in the project/code. The registry variable acts as a global variable which can be used anywhere. Here are the functions to register, unregister and fetch a registry variable. register(): register a variable unregister(): unregister a variable registry(‘VARIABLE_NAME’): fetch registry variable … Read more