Jump to content

watermark images then save them


james_byrne

Recommended Posts

I would like to have a script on my site to eather watermark images on the fly, or to actually save the watermarked images. I have found this tutorial and it seems to work great, all except when the images is suppose to get displayed it does not show the image but instead shows wired caracters, like if you opend a jpg image in notepad. I just know i am missing something. But with this script is there anyway to save the watermarked image. Let me know please. Thank you

 

A link to the script: http://www.sitepoint.com/article/watermark-images-php

Link to comment
https://forums.phpfreaks.com/topic/116254-watermark-images-then-save-them/
Share on other sites

You can save the images by specifying the filename parameter in the imagejpeg() function.

 

As for the odd output, did you remember to send a proper header? If you did, then try uncommenting that line and the imagejpeg() line and check to see if you get any errors displayed. I can't remember which of these problems results in the odd output.

ok so here is the code i am using, that is not working. But my current problem has changed a little bit, i have got it to display the image now, but it displays it with a box in the corner that has a black background then my watermark in that box. The watermark is a transparent png image though. and that should allow it to work the way i want it to. Below is my code, please let me know if you can help. Thanks in advance for the help.

 

<?

header('content-type: image/jpeg');  

    $src = "upload/cat15-id33.jpg";
$watermark = imagecreatefrompng('watermark.png');  
$watermark_width = imagesx($watermark);  
$watermark_height = imagesy($watermark);  
$image = imagecreatetruecolor($watermark_width, $watermark_height);  
$image = imagecreatefromjpeg($src);  
$size = getimagesize($src);  
$dest_x = $size[0] - $watermark_width - 5;  
$dest_y = $size[1] - $watermark_height - 5;  
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);
imagejpeg($image);
imagedestroy($image);  
imagedestroy($watermark);


?>

ok, i have found out that the code i am using was not that great, the article uses some wrong things. I have fixed it up now though. The only issue i am having is centering the watermark. I think the most effective way to do that though. Would be through making the watermark image larger. And making it centered.

 

I appreciate all your guyses help.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.