BlackAce Posted June 14, 2012 Share Posted June 14, 2012 The script below runs without any errors (I've enabled all PHP errors just to be sure). But the file that is saved out does not have the watermark on it anywhere. Just the original source image. Here is a live example for you to view: http://www.ahsnewsline.com/watermark.php <?php $thumb_dir = "img/"; $perm_name = "wm_news001.jpg"; $filename = $thumb_dir.$perm_name; echo "<strong>WATERMARK IMAGE:</strong><br/><img src='img/video-icon.png'/>"; echo "<br/><strong>BEFORE:</strong><br/><img src='$filename'/>"; echo "<br/>$filename<br/><br/>"; $watermark = imagecreatefrompng('img/video-icon.png'); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); $image = imagecreatefromjpeg($filename); $size = getimagesize($filename); $dest_x = $size[0] - $watermark_width; $dest_y = $size[1] - $watermark_height; imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height); imagejpeg($image); imagedestroy($image); imagedestroy($watermark); echo "<br/><hr/><br/><strong>AFTER:</strong><br/><img src='$filename'/>"; echo "<br/>$filename"; ?> NOTE: This version uses imagecopy() instead of imagecopymerge() due to it's PNG-24 support. And yes, I was using PNG-8 when I was using the imagecopymerge() function. Regardless, it's still not working. Any ideas? Link to comment https://forums.phpfreaks.com/topic/264187-watermarking-using-imagecopymerge-or-imagecopy-does-not-add-watermark/ Share on other sites More sharing options...
mrMarcus Posted June 14, 2012 Share Posted June 14, 2012 Add a content-type header: ... imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height); header('Content-type: image/jpeg'); imagejpeg($image); ... EDIT: Oh, but you'll have to remove the echo's as they'll throw a "headers already sent..." error. Link to comment https://forums.phpfreaks.com/topic/264187-watermarking-using-imagecopymerge-or-imagecopy-does-not-add-watermark/#findComment-1353858 Share on other sites More sharing options...
BlackAce Posted June 14, 2012 Author Share Posted June 14, 2012 This is part of a larger script that is processing form submissions. I realize that I failed to include the 2nd parameter of imagejpeg() which is the location where I'd like to save the new file. Thus: imagejpeg($image, $filename); Thank you for your help, sometimes it just helps to write this stuff out. Link to comment https://forums.phpfreaks.com/topic/264187-watermarking-using-imagecopymerge-or-imagecopy-does-not-add-watermark/#findComment-1353952 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.