How to add watermark to image using php gd
Onelinerhub
Posted on October 6, 2022
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.
💖 💪 🙅 🚩
Onelinerhub
Posted on October 6, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.