2

I don't if it is possible to add watermark to product images programmatically. Here is my situation:

On the category pages and the product details pages, I want to show the product images WITHOUT watermarks. However, we have a function that a customer can add some of the products to their favorites, and we can send an email to the customer along with their favorite product images. Within the email, I want all the product images to be watermarked.

If I setup the watermark in Magento Admin, the product images on category pages will have watermarks, which is not what I want. Can Magento do some magic like $product->getWatermarkedImageUrl() when I want to watermark images?

I am using Magento 1.6.1.0 Community version.

Thanks.

3
  • Do you have separate images with watermarks already on the image? Or do you want to somehow use php to inject watermarks onto images? Commented Dec 5, 2014 at 17:00
  • Well, having separate images is the last thing I will do. I am trying to avoid that if I can do something in magento. And using php looks like the same option with having separate images. Basically, what I want is to save the watermarked images automatically into magento media (cached images) and can retrieve the url, just like the normal product images. I am just wondering if magento can do some magic, if not, I have some other solutions.
    – CharlesDou
    Commented Dec 5, 2014 at 17:16
  • I wasn't aware that magento was capable of this, thanks. Commented Dec 5, 2014 at 17:24

1 Answer 1

3

You could manually create the watermark image and store them in a separate folder, then use the url to these images in your email

See Magento: Create Watermark Image

// update with  path to product image
$mainImage = Mage::getBaseDir('media') . DS . 'test' . DS . 'image.jpg';

//update with path to watermark
$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');
2
  • It looks like that's the easiest way to do. Thanks.
    – CharlesDou
    Commented Dec 5, 2014 at 17:38
  • FYI this did not work for me without adding the following line: $image->setWatermarkImageOpacity(30);
    – Louis B.
    Commented Aug 26, 2020 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.