If you are a professional or a newbie photographer you will probably want to protect your photos from being stolen and used for free. Using PHP you can create different types of watermarks on all of your images. I am going to show you a way how to dynamically put a text messages on your images. What you need is a JPG image file and a font file used for generate the watermark message. I am going to use arial font which you can also download.
Below you can find a watermarkImage() image function which takes 3 parameters ($SourceFile, $WaterMarkText, $DestinationFile) and creates an watermarked image from the source image specified. The first parameter - $SourceFile - is the full server path to the JPG image that you are going to watermark. The second one - $WaterMarkText - is the text message that you want to use for the watermark. And the last parameter - $DestinationFile - can either be blank or full server path to a new file which will be the source file with watermark text on it. What this function does is to read the source file, then create a new image object (using the imagecopyresampled() function). Then using the Arial.ttf font file and the imagettftext() function it writes the WaterMarkText onto the image. The last IF statement checks if it should save a new watermarked file or should just display it on the screen.
You need to download the arial.ttf file and upload it on your server. Then create a new PHP file and copy and paste the above function in it. Next 4 lines are used to set the Source file, Watermark text message and Destination file. If you want to just display the watermarked image you need to leave the $DestinationFile variable empty ($DestinationFile=''; ). Also please make sure that for source file and destination file you include the full server path and the image file name. If you want to change the position of the watermark message on your images you can chage that line imagettftext($image_p, $font_size, 0, 10, 20, $black, $font, $WaterMarkText);
| Comments |
| Sam George posted on 2008-06-09 14:30:52 |
| Fantastic, Congratulations! Thank you so much! |
| Mr. Watermark posted on 2008-05-26 04:15:38 |
| I just implemented the version of this that uses transparency. It works like a charm! Thank you so much! |
| Paul posted on 2008-04-12 21:45:19 |
| Great script and easy to follow. However, I've got a problem. I've got a php page which creates a watermarked image. The destination filename is blank so it displays on screen. When I use Firefox, the watermarked image is a jpg (about 400KB) but when I use IE it is a bmp (about 2.5MB). The original images are all jpg. Any ideas what I've done wrong? ------------------- Veselin: can you post your code or send it to our email address if it is too long |
| jit posted on 2008-02-07 07:46:08 |
| Ash posted on 2008-02-06 14:49:40 thank you Ash for semi-transparent ;) |
| Ash posted on 2008-02-06 14:49:40 |
| Hey, sorry for the double post, but i worked it out. replace $black = imagecolorallocate($image_p, 0, 0, 0); with $black = imagecolorallocatealpha($image_p, 255, 255, 255, 50); hope it helps somebody else |
| Ash posted on 2008-02-06 14:15:27 |
| Hi, great tutorial! I have been looking at the script and I was wondering if it would be possible to make the watermark text semi-transparent? Thank you for any help. |
| Amit posted on 2007-10-29 15:20:31 |
| This is a cool dude..... |
| pawan posted on 2007-07-26 12:41:51 |
| The above mentioned function is only to apply watermark text on image.......... But there is no function to apply watermark image on image... Please provide me that script |
| paul posted on 2007-07-18 19:18:32 |
| I got the function running but returns a full screen of garbage text.. is something not installed on my server? Paul |
| salik posted on 2007-07-12 22:24:54 |
| this is not working on gif file formate please do for gif file formate ---------------------- Veselin: yes this is only for JPG files |