Using PHP GD library to adding watermark is as simple as merging 2 images.
First, we create gd image from photo to add watermark to:
$bg = imagecreatefromjpeg('photo.jpg');
Next, we create gd image from watermark file (logo.png
) and get it's size:
$wm = imagecreatefrompng('logo.png');
$wm_size = getimagesize('logo.png');
Now place watermark at 25 pixels from top & left borders:
imagecopy($bg, $wm, 25, 25, 0, 0, $wm_size[0], $wm_size[1]);
Finally, save resulting JPG image to result.jpg
:
imagejpeg($bg, 'result.jpg');
Get and contribute more PHP GD code solutions.
Top comments (0)