Last active
January 24, 2017 09:33
-
-
Save vishnu1991/024ae1f838098c887f8b7a2bf5b6364b to your computer and use it in GitHub Desktop.
Add watermark to jpg images php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$bg_img='bg.jpg'; //path to background (JPG ext) | |
$logo_img='logo.png'; // path to logo (PNG ext.) | |
list($width_of_bg, $height_of_bg) = getimagesize($bg_img); // to calculate background image width and height | |
list($width_of_logo, $height_of_logo) = getimagesize($logo_img); //to calculate logo image width and height | |
//for bottom right | |
$logo_loc_width=$width_of_bg-$width_of_logo; | |
$logo_loc_height=$height_of_bg-$height_of_logo; | |
// for different logo placement options see below comment | |
$bottom_image = imagecreatefromjpeg($bg_img); | |
$top_image = imagecreatefrompng($logo_img); | |
imagesavealpha($top_image, true); | |
imagealphablending($top_image, true); | |
imagecopy($bottom_image, $top_image, $logo_loc_width, $logo_loc_height, 0, 0, $width_of_logo, $height_of_logo); | |
header('Content-type: image/png'); | |
imagepng($bottom_image); // for outputting image to browser | |
//imagepng($bottom_image, 'outputfile.png'); //to save file to server (uncomment this line for saving file to server) | |
imagedestroy($bottom_image); | |
imagedestroy($top_image); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
**Todos / Areas of improvement **
If you have any problem/suggestion/bug/issue then pls comment to let us know!