Watermarking with PHP is not a complex thing. Google will list hundreds of solutions using GD or ImageMagick. But the complexity starts when I need custom positioning, rotation, repetition etc. Though all those things are just a matter of tweaking some options in ImageMagick or GD, discovering them every time is a pain. So I just encapsulated all those tweakings in a PHP library.
Check it – ajaxray/php-watermark
It supports watermarking on Image and PDF. You may watermark with a text or an image logo. Also it have self-explanatory API for customizing font, font-size, position, tileing, opacity, rotation etc.
How to use?
<?php // Initiate with source image or pdf $watermark = new Watermark('/path/to/source.jpg'); // Customize some options $watermark->setFontSize(48) ->setRotation(30) ->setOpacity(.4); // Watermark with Text $watermark->withText('ajaxray.com', 'path/to/output.jpg'); // Watermark with Image $watermark->withImage('path/to/logo.png', 'path/to/output.jpg');
Here are a few example watermarked files –
- Watermarking with text on Image or tiled text on Image
- Watermarking with Image on Image
- Watermarking with text on PDF
- Watermarking with Image on PDF
If you think a commonly required customization option is missing, please let me know or just submit a PR. Thanks!