Home » Magento

Magento: Create Watermark Image

12 March 2010 1,338 views 2 Comments Popularity: 15% Share/Bookmark

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

Related posts:

  1. Magento: Crop image
  2. Magento: Rotate image
  3. Magento: Get width height of image using Varien_Image class
  4. Magento: Resize Image
  5. Magento: Custom function to resize image proportionally

2 Comments »

  • How To Use Camtasia Studio 6 -Tutorial said:

    [...] Magento: Create Watermark Image | Mukesh Chapagain's Blog [...]

  • sree said:

    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 ?

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.