Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors',1); // enable php error display for easy trouble shooting
- error_reporting(E_ALL); // set error display to all
- function resizePng($file, $newfile, $nWidth) {
- list($width, $height, $type, $attr) = getimagesize($file);
- $ratio = $width / $height;
- $nHeight = $nWidth * $ratio;
- $data = imagecreatefrompng($file);
- $newImg = imagecreatetruecolor($nWidth, $nHeight);
- imagealphablending($newImg, false);
- imagesavealpha($newImg,true);
- $transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127);
- imagefilledrectangle($newImg, 0, 0, $nWidth, $nHeight, $transparent);
- imagecopyresampled($newImg, $data, 0, 0, 0, 0, $nWidth, $nHeight, $width, $height);
- return imagepng($newImg, $newfile);
- }
- function watermark($watermark, $image, $newfile) {
- // Load the stamp and the photo to apply the watermark to
- $stamp = imagecreatefrompng($watermark);
- $data = imagecreatefromjpeg($image);
- // Set the margins for the stamp and get the height/width of the stamp image
- $marge_right = 10;
- $marge_bottom = 10;
- $sx = imagesx($stamp);
- $sy = imagesy($stamp);
- // Copy the stamp image onto our photo using the margin offsets and the photo
- // width to calculate positioning of the stamp.
- imagecopy($data, $stamp, imagesx($data) - $sx - $marge_right, imagesy($data) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
- return imagejpeg($data, $newfile, 90);
- }
- echo (resizePng('logo.png','nlogo.png', 200) && watermark('nlogo.png','photo.jpg','watermarked.jpg')) ? 'Completed' : 'Failed';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement