Error using Imagine\Image to watermark images

1.5k views Asked by At

I am trying to watermark images using the Imagine library (on a CakePHP project). Cropping images works fine - watermarking does not. I use the example from the Imagine website:

$imagine = new Imagine\Gd\Imagine();

$watermark = $imagine->open('/my/watermark.png');
$image     = $imagine->open('/path/to/image.jpg');
$size      = $image->getSize();
$wSize     = $watermark->getSize();

$bottomRight = new Imagine\Image\Point($size->getX() - $wSize->getX(), $size->getY() - $wSize->getY());

$image->paste($watermark, $bottomRight);

The original example doesn't state an instantiation procedure, so I added what I found on the page. Doing so yields the following error:

 Call to undefined method Imagine\Image\Box::getX() 

How do I use it correctly?

2

There are 2 answers

0
afshin akhgar On

I've used it like this and it's worked.

\Imagine\Image\Box::getX()

test it please

0
Alex Agrazal On

Replace this:

    $bottomRight = new Imagine\Image\Point($size->getX() - $wSize->getX(), $size->getY() - $wSize->getY());

With this:

    $bottomRight = new \Imagine\Image\Point($size->getWidth() - $wSize->getWidth(), $size->getHeight() - $wSize->getHeight());