0

Sometimes the pre-defined watermark positions are not enough and we may need custom positions, such as 25% below the middle center, etc.

I found this method but it seems protected.

Is there any way to programmatically set the position of a watermark? Such as by position of pixels from the top left of the image? For now I can set size and opacity of the watermark programmatically:

$this->helper('catalog/image')->init($_product, 'image')
    ->constrainOnly(TRUE)
    ->keepAspectRatio(TRUE)
    ->keepFrame(FALSE)
    ->setWatermarkImageOpacity(6)
    ->setWatermarkSize(
        iGetWatermarkSize(600)
    )
    ->resize(600, null)

Wherein iGetWatermarkSize() is my in-house function that returns the size string for the watermark according to the width of the subject image.

I think it's sensible to have a method to set the position of a watermark in Magento but found nothing relevant in Google in this regard. Is there such a method or way for me to do this?

1 Answer 1

2

There is an public function Mage_Catalog_Helper_Image::watermark()

But you have to pass watermark image to this function as parameter.

/**
 * Add watermark to image
 * size param in format 100x200
 *
 * @param string $fileName
 * @param string $position
 * @param string $size
 * @param int $imageOpacity
 * @return Mage_Catalog_Helper_Image
 */
public function watermark($fileName, $position, $size=null, $imageOpacity=null)
{
    $this->setWatermark($fileName)
        ->setWatermarkPosition($position)
        ->setWatermarkSize($size)
        ->setWatermarkImageOpacity($imageOpacity);
    return $this;
}
2

Your Answer

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

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