Home » Magento12 March 2010

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);

// set watermark image width 
$image->setWatermarkWidth(100);

// set watermark image height
$image->setWatermarkHeigth(100);

// create watermark image
// watermark($watermarkImage, $positionX=0, $positionY=0, $watermarkImageOpacity=30, $repeat=false)
$image->watermark($watermarkImage);
 
// save the watermark image
$image->save(Mage::getBaseDir('media'). DS . 'test' . DS . 'new.jpg');

Code Explanation

In the code above, you can see that I have an image named image.jpg inside media/test/ directory.
I have a watermark image named watermark.jpg.
I have set the watermark image width and height to 100px. You can omit these two functions if you don’t want to resize the watermark image.
The new image with watermark is saved inside media/test/ directory as new.jpg.

Hope this helps and thanks for reading.

From Mukesh Chapagain's Blog, post Magento: Create Watermark Image

php magento mukesh chapagain

Get New Post by Email

Find me on

Facebook Twitter Google+ LinkedIn RSS Feed
  • Pingback: How To Use Camtasia Studio 6 -Tutorial

  • sree

    hi
    Hi iam new to megento and php, would u please tell me where to implement u r code. u r code seems for for single image, how to make watermark for bulk images ?

  • http://www.infotrade.co.il Sharon

    Hi,

    Do you have an idea how can i make only selected images with watermarks?
    I’m using Mag 1.4.1.1 and the water mark is working well but there are some categories and specific products that requires watermark. I though abt something with attribute and combining it with the water mark function (I’m not a code at all, this is an idea.)

    Thanks!

  • Bryan

    Yes, can you show us how and where to put your code?

  • Rav

    I need some help with this

  • Jon

    It would be nice if you could tell us exactly what files we need to add that line of code to..