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: 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: Get next and previous post link in Laravel
Recommanded Articles
- How to check YouTube video exist Laravel validation
- JQuery AJAX image upload with form data in PHP
- Insert Update Delete in PHP MySQL
- How to make image background transparent using PHP
- Paypal credit card payment on website in PHP
- Capture page screenshot by URL PHP script
- Insert Update Delete Select query in WordPress
- How to parse an URL in PHP
- How to increase website speed
- How to get all UK addresses by postal code
Latest Comments
Tanya
28 Dec 2020