Re: Watermarking of images
| From: | Robert Cummings | Date: | Mon, 11 May 2009 17:49:40 +0000 |
| Subject: | Re: Watermarking of images | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-292454@lists.php.net to get a copy of this message | ||
On Mon, 2009-05-11 at 10:39 -0700, Michael A. Peters wrote:
> tedd wrote:
> > At 12:04 AM -0700 5/11/09, Michael A. Peters wrote:
> >> That site is also coded in php so I'm guessing that the watermark is
> >> added using a php technology.
> >>
> >> Can someone enlighten me on how that is done?
> >>
> >> Also, while not php related, could someone enlighten me of a really
> >> good font to use for watermarking images?
> >
> >
> > Michael:
> >
> > Here's an example with code:
> >
> > http://webbytedd.com/b/watermark/
> >
> > Cheers,
> >
> > tedd
> >
>
> This is what I'm doing, it seems to work -
>
> $im=imagecreatefromjpeg($impath);
> $text_font="LT_51250.TTF";
> imageantialias($im, true);
> $imw=imagesx($im);
> $imy=imagesy($im);
> $string="© " . $somestring;
> $lbox=imageftbbox($fontsize, 0, $text_font, $string);
> $color = imagecolorallocate ($im, 255,255,255);
> $bcolor = imagecolorallocate ($im, 0,0,0);
>
> imagefttext($im,$fontsize,0,($xcord - 1),$ycord,$bcolor,$text_font,$string);
>
> imagefttext($im,$fontsize,0,($xcord + 1),$ycord,$bcolor,$text_font,$string);
>
> imagefttext($im,$fontsize,0,$xcord,($ycord - 1),$bcolor,$text_font,$string);
>
> imagefttext($im,$fontsize,0,$xcord,($ycord + 1),$bcolor,$text_font,$string);
>
> imagefttext($im,$fontsize,0,$xcord,$ycord,$color,$text_font,$string);
>
> header ("Content-type: image/jpeg");
> imagejpeg($im);
> imagedestroy($im);
>
> where $impath is the filesystem path to where image is stored, $xcord is
> x coordinate, $ycord is y coordinate.
>
> It does it very nicely.
> (I changed font to helvetica - it seems to work a little better for this
> than lucida mono, largely because it isn't monospace).
Note that the 1 pixel offset is optional. You could use 2 or more and
get a thicker black border. It might even be nicer looking if you did
all eight directions.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP