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
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.

Link to comment
Share on other sites

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);


?>

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.