PHP script to add transparent logo on image

PHP script to add transparent logo on image

I will show you how you can add transparent logo or icon watermark using php script on a image(s) and save result image(s). You can align logo or icon using perimeters which are used in imagecopy() php function.

For single image Copy and paste the below code in your php file and run.I'm using the following code to add image or logo on an image.

Also Read: PHP script to add transparent logo on multiple images

<?php
//$logo is the logo or icon which you to add on a image
//$background is the background image
$logo = imagecreatefrompng('1.png');
$background = imagecreatefromjpeg('2.jpg');
$size = getimagesize('2.jpg');

// you can align the logo according the size of the background image
$marge_right = $size[0] - 130;
$marge_bottom = 1;
$sx = imagesx($logo);
$sy = imagesy($logo);

//pass the size, images parametres in imagecopy() function 
imagecopy($background, $logo, imagesx($background) - $sx - $marge_right, imagesy($background) - $sy - $marge_bottom, 0, 0, imagesx($logo), imagesy($logo));
header('Content-type: image/png');
$imgName = time() .".png";
imagepng($background, $imgName);

//create and save new image in your current directory
imagedestroy($background);
?>

Also Read: PHP script to add transparent logo on multiple images
Also Read: Get next and previous post link in Laravel

I will show you how you can add transparent logo or icon watermark using php script on a image(s) and save result image(s). You can align logo or icon using perimeters which are used in imagecopy() php function.

For single image Copy and paste the below code in your php file and run.I'm using the following code to add image or logo on an image.

Also Read: PHP script to add transparent logo on multiple images

<?php
//$logo is the logo or icon which you to add on a image
//$background is the background image
$logo = imagecreatefrompng('1.png');
$background = imagecreatefromjpeg('2.jpg');
$size = getimagesize('2.jpg');

// you can align the logo according the size of the background image
$marge_right = $size[0] - 130;
$marge_bottom = 1;
$sx = imagesx($logo);
$sy = imagesy($logo);

//pass the size, images parametres in imagecopy() function 
imagecopy($background, $logo, imagesx($background) - $sx - $marge_right, imagesy($background) - $sy - $marge_bottom, 0, 0, imagesx($logo), imagesy($logo));
header('Content-type: image/png');
$imgName = time() .".png";
imagepng($background, $imgName);

//create and save new image in your current directory
imagedestroy($background);
?>

Also Read: PHP script to add transparent logo on multiple images
Also Read: Get next and previous post link in Laravel

Please let me know what your thoughts or comments are on this article. If you have any suggestion or found any mistake in this article then please let us know.

Latest Comments

Tanya
Tanya
28 Dec 2020

Working fine at my end. Can someone please let me know how can I align icon to top left

Add your comment

Close