Home » Magento

Magento: Create Watermark Image

12 March 2010 4,733 views Popularity: 10% Share/Bookmark

email

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.

Related posts:

  1. Magento: Get width height of image using Varien_Image class
  2. Magento: Crop image
  3. Magento: Rotate image
  4. Magento: Custom function to resize image proportionally
  5. jQuery: Grey out background and preview image as popup
  6. Magento: Resize Image
  7. Magento: Get height and width of Image
  8. jQuery: Preview Image with Zoom Effect
  9. jQuery: Preview Image with Tooltip Effect
  10. Magento: Create CMS Page & Static Block programmatically
  • http://www.easyvideoeditingsoftware.net/how-to-use-camtasia-studio-6-tutorial.htm How To Use Camtasia Studio 6 -Tutorial

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

  • 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