Put watermark on images using PHP

posted on June 30, 2006, 11:41 pm
Comments
Jim posted on December 2, 2008, 1:03 am
Hi. I have PHP and GD (bundled (2.0.28 compatible) on my server but I get a blank screen with this script. Any ideas?

Noel posted on November 26, 2008, 2:12 pm
Do I have to have something installed on my server as when I put that code in, nothing happens, it gives me a blank screen
--------------
Veselin: yes you need PHP with GD support and the code correctly placed.

silva posted on November 15, 2008, 2:32 pm
hi,
i have already check this coding.but it will display like this error:"Warning: imagettftext() [function.imagettftext]: Invalid font filename in C:xampphtdocssamplewatermarkwatersample3.php on line 20". but all files are in one folder.arial.ttf also in the same folder. so, pls help me to solve this.thanks

silva posted on November 15, 2008, 12:49 pm
This is great script . I'm working in local host now , where i should upload the font file .i already download the arial.ttf and save in script folder. when i run this script, i got warning message like this: "
Warning: imagettftext() [function.imagettftext]: Invalid font filename in C:xampphtdocssamplewatermarkwatersample3.php on line 20 ". but destinatiion place have a image without watermark text. so, pls, help me.how to display the watermark text on the destination place.ok bye
------------------
Veselin: the file should be in the same folder where your PHP files are

Loo posted on October 6, 2008, 3:28 pm
This is brilliant, exactly what I was looking for. I did mod it slightly as I wanted the watermark through the middle of the image (it's easy to cut the edge off with the watermark on) so I used the following:

list($width, $height) = getimagesize($SourceFile);
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($SourceFile);
$left = ($width / 7) ;
$top = ($height / 3) ;
$bot = ($top * 2) ;
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height);
$black = imagecolorallocatealpha($image_p, 255, 255, 255, 50);
$font = 'arial.ttf';
$font_size = 10;
imagettftext($image_p, $font_size, 0, $left, $bot, $black, $font, $WaterMarkText);

I had a website address to watermark, hence the margin from the left being small. Thanks to everyone who has contributed here, you saved me a lot of headaches.

Diaa Bendary posted on September 13, 2008, 4:23 pm
This is great script . I'm working in local host now , where i should upload the font file .
If you can make this script with watermark photo instead of font
Best regards
----------
Veselin: it should be in the same folder where your PHP script is

Khawaja Abid posted on August 13, 2008, 11:14 am
I utilized the above code it was really great and help me alot i really thank full to you

and pawan asked for image on image for that please use this may its help

$dest = imagecreatefromjpeg('2.jpg');
$src = imagecreatefromgif('php2.gif');

imagecopymerge($dest, $src, 0, 0, 0, 0, 800, 600, 75);

header('Content-Type: image/gif');

hope this help you all

thanks

Matt posted on August 1, 2008, 12:57 pm
I know this is a really old thread but does anyone know how i can add a horizontal coloured bar/background behind the overlayed text because some of my images are dark and some light so i need to set a coloured background for he text? thanks
--------------
Veselin: you should create a new image for your watermark and then using imagecopymerge() to copy that image over your own images.

http://www.php.net/manual/en/function.imagecopymerge.php

Saul posted on July 29, 2008, 8:32 pm
I'm trying to download the arial.ttf file that you reference on your site but it is blocked with a password... What do I have to do to download the font?
---------
Veselin: sorry, you can download it now

Sam George posted on June 9, 2008, 2:30 pm
Fantastic, Congratulations! Thank you so much!

Pages:   1   2   3   4   
   
If you have any additions, suggestions or modifications for this example please contact us or use the form below.
   
Your name:
Your email: (email address will not be posted on the web site)
Comment:
Verification