I’m using https://github.com/php-imagine/Imagine (as use ImagineImagickImagine
) to handle my images. I’m applying a transparent (alpha-channel) PNG image as watermark, following the docs here https://imagine.readthedocs.io/en/stable/usage/introduction.html#image-watermarking :
$watermark = $imagine->open('/my/watermark.png');
$image = $imagine->open('/path/to/image.jpg');
$size = $image->getSize();
$wSize = $watermark->getSize();
$bottomRight = new ImagineImagePoint($size->getWidth() - $wSize->getWidth(), $size->getHeight() - $wSize->getHeight());
$image->paste($watermark, $bottomRight);
It works, but I’d like to reduce the opacity of the watermark, so it’s less in-your-face.
I tried to search the docs via https://imagine.readthedocs.io/en/stable/search.html , but it doesn’t seem to work.
2
Answers
Looking at the code, it appears that the
paste()
method has an alpha argument built right into it:Since the argument is optional, and you’re not overriding in your example, you’re getting the default value of 100. To override, just explicitly provide a value less than 100 for the third parameter:
Note if you use a modern IDE, you’ll get autocompletion on method arguments, and this sort of feature will become trivially easy to discover:
Assuming you are using the PHP library Imagine for image manipulation, you can apply transparency to a watermark by adjusting the alpha channel of the image. Here’s an example using Imagine library with GD:
In this example, the apply mask method is used to adjust the opacity of the watermark. The $opacity variable determines the level of transparency, where 0 is fully transparent, and 100 is fully opaque. You can modify the $opacity value to achieve the desired level of transparency for your watermark.
Make sure to replace ‘path/to/your/image.jpg’ and ‘path/to/your/watermark.png’ with the actual paths to your original image and watermark image. Additionally, adjust the positioning and save paths as needed for your specific use case.