Is there a way to save the watermarked $image to a file? I tried using fopen and fwrite, but they didn’t work.
If you’re using a png 24 using alpha transparency for your watermark image (e.g. open new file in photoshop, type “COPYRIGHT MESSAGE”, drop the opacity by about 50% and “save for web” using png24 and saving transparency vaules), you might want to put the watermark in the middle of the image.
To put the watermark slap bang in the middle of the image . . . this should work:
$dest_x = ($size[0] / 2) - ($watermark_width / 2);
$dest_y = ($size[1] / 2) - ($watermark_height / 2);
($size[0] / 2) and ($size[1] / 2) will find the “dead center” of the image to be watermarked which would place the watermark’s top left corner in the center of the screen. To shift the watermark left and up we just work out half of the watermarks width and height then subtract it from the “dead center” calculation.
I am trying to use this cool code in my .htaccess file, but my server keeps giving me back Http Error 500.
Would you kindly explain how I could get this to work? I have a bunch of listings on eBay and would like to watermark all the images.
Thanks!
nevermind, got it sorted…the problem was that I had put all the files in my images directory. Moved them to root and we are good to go.
Thanks all!
i would recommend “imagecopyresampled” function rather than “imagecopymerge” when using transparent png.
Also, if you are using imagecopyresampled to resize a watermark with transparency, (so it will fit your image better) it will become opaque. There is a workaround for this located here
this code isnt working… problem is in header… i dont know why… if any one know do help me in this regard.
if you copy & paste this code, it’s unlikely to work, because of tabs, spaces at ends of lines, etc. better to retype it. in particular, if the content-type header winds up with a tab instead of a space, it won’t be recognized.
Thanks for a great article. It was just what I needed.
Hi All!
Please help me out. I am able to create image with watermark. But I am not able to copy that image into some other location. It is just displaying in the browser.
Thanks in Advance.
Jyotsna. Ch.
This code does not work for me either. Maybe it is a permissions issue. Hmm…
Codes working fine in IE6 but not in Firefox 1.5.0.4 - any ideas?
When I use this code (at upon) for a php file. When run it error :
<br />
<b>Warning</b>: imagecopy(): supplied argument is not a valid Image resource in <b>c:\appserv\www\ch15\duc.php</b> on line <b>11</b><br />
<br />
<b>Warning</b>: imagejpeg(): supplied argument is not a valid Image resource in <b>c:\appserv\www\ch15\duc.php</b> on line <b>12</b><br />
<br />
<b>Warning</b>: imagedestroy(): supplied argument is not a valid Image resource in <b>c:\appserv\www\ch15\duc.php</b> on line <b>13</b><br />
Why ? Please help me.
Many Thanks
Thank you very much
But, same i said : when i use “png” image for watermark it is not tran
rwduc: You do not have gd library
Ok ! I have used it. But why I use “Watermark” is PNG file but it is opaque.
Plz help me !
Thanks.
What’s the point in using 100% for the last parameter of imagecopymerge() ?
Quote PHP manual: “when 100 this function behaves identically to imagecopy()”.
And I think you should use a random value for this(range 40-60%) to make it impossible for other scripts to substract the watermark pixel values.
But dispite this, good tutorial !
Wow, this has been a great tutorial and a great thread as well, thanks guys! After reading the article originally, I just couldn’t work out how to call it, well thats now sorted, Im going to attempt to do the .htaccess coding to secure my images now.
That is simple and cool, thanks!
thanks for it, i was thinking to watermark my project’s images (not ready yet) and u gave me a great idea.