soup4you2
October 9th, 2003, 22:10
Here's a nice php script to watermark your images..

Supports JPGs and PNGs.
You need GD library to make it works (included in PHP since v4.3.0, but you have to enable it in php.ini)
You need a True Type (.TTF) font.
The hotspot feature is approximated.

Hot Spots:
1-2-3
4-5-6
7-8-9

0 = Free X/Y text coordinates.

Simple usage examples:

[code:1:82a2167005]
<IMG SRC="watermark.php?wmimg=image.jpg">
<IMG SRC="watermark.php?wmimg=image.jpg&wmtext=Hello%20 World" BORDER=0 ALT="test image" TITLE="this is a test" ALIGN=LEFT>
[/code:1:82a2167005]


[code:1:82a2167005]

function watermark($img,$text="[date]",$datfmt="Y-m-d",$font="ARIAL.TTF",$font_size=12,$rgbtext="FFFFF F",$rgbtsdw="000000",$hotspot=8,$txp=0,$typ=0,$sxp =1,$syp=1) {

$suffx=substr($img,strlen($img)-4,4);
if ($suffx==".jpg" || $suffx=="jpeg" || $suffx==".png") {
$text=str_replace("[date]",date($datfmt),$text);

if ($suffx==".jpg" || $suffx=="jpeg") {
$image=imagecreatefromjpeg($img);
}
if ($suffx==".png") {
$image=imagecreatefrompng($img);
}

$rgbtext=HexDec($rgbtext);
$txtr=floor($rgbtext/pow(256,2));
$txtg=floor(($rgbtext%pow(256,2))/pow(256,1));
$txtb=floor((($rgbtext%pow(256,2))%pow(256,1))/pow(256,0));

$rgbtsdw=HexDec($rgbtsdw);
$tsdr=floor($rgbtsdw/pow(256,2));
$tsdg=floor(($rgbtsdw%pow(256,2))/pow(256,1));
$tsdb=floor((($rgbtsdw%pow(256,2))%pow(256,1))/pow(256,0));

$coltext = imagecolorallocate($image,$txtr,$txtg,$txtb);
$coltsdw = imagecolorallocate($image,$tsdr,$tsdg,$tsdb);

if ($hotspot!=0) {
$ix=imagesx($image); $iy=imagesy($image); $tsw=strlen($text)*$font_size/imagefontwidth($font)*3; $tsh=$font_size/imagefontheight($font);
switch ($hotspot) {
case 1:
$txp=$txp; $typ=$tsh*$tsh+imagefontheight($font)*2+$typ;
break;
case 2:
$txp=floor(($ix-$tsw)/2); $typ=$tsh*$tsh+imagefontheight($font)*2+$typ;
break;
case 3:
$txp=$ix-$tsw-$txp; $typ=$tsh*$tsh+imagefontheight($font)*2+$typ;
break;
case 4:
$txp=$txp; $typ=floor(($iy-$tsh)/2);
break;
case 5:
$txp=floor(($ix-$tsw)/2); $typ=floor(($iy-$tsh)/2);
break;
case 6:
$txp=$ix-$tsw-$txp; $typ=floor(($iy-$tsh)/2);
break;
case 7:
$txp=$txp; $typ=$iy-$tsh-$typ;
break;
case 8:
$txp=floor(($ix-$tsw)/2); $typ=$iy-$tsh-$typ;
break;
case 9:
$txp=$ix-$tsw-$txp; $typ=$iy-$tsh-$typ;
break;
}
}

ImageTTFText($image,$font_size,0,$txp+$sxp,$typ+$s yp,$coltsdw,$font,$text);
ImageTTFText($image,$font_size,0,$txp,$typ,$coltex t,$font,$text);

if ($suffx==".jpg" || $suffx=="jpeg") {
header("Content-type: image/jpg");
imagejpeg($image);
}
if ($suffx==".png") {
header("Content-type: image/png");
imagepng($image);
}

imagedestroy($image);

}
}

if (isset($wmimg)) {
if (!isset($wmtext)) {$wmtext="[date]";}
if (!isset($wmdatfmt)) {$wmdatfmt="Y-m-d";}
if (!isset($wmfont)) {$wmfont="ARIAL.TTF";}
if (!isset($wmfont_size)) {$wmfont_size=12;}
if (!isset($wmrgbtext)) {$wmrgbtext="FFFFFF";}
if (!isset($wmrgbtsdw)) {$wmrgbtsdw="000000";}
if (!isset($wmhotspot)) {$wmhotspot=8;}
if (!isset($wmtxp)) {$wmtxp=0;}
if (!isset($wmtyp)) {$wmtyp=0;}
if (!isset($wmsxp)) {$wmsxp=1;}
if (!isset($wmsyp)) {$wmsyp=1;}

watermark($wmimg,$wmtext,$wmdatfmt,$wmfont,$wmfont _size,$wmrgbtext,$wmrgbtsdw,$wmhotspot,$wmtxp,$wmt yp,$wmsxp,$wmsyp);
}
[/code:1:82a2167005]


Sample HTML page:

[code:1:82a2167005]
<HTML>
<HEAD>
<TITLE>Watermark test</TITLE>
</HEAD>
<BODY>

This is a watermarked picture:
<P>
<IMG SRC="watermark.php?wmimg=image.jpg&wmtext=TEST">
<P>
END

</BODY>
</HTML>
[/code:1:82a2167005]

you also have wmtext=[date]

soup4you2
October 9th, 2003, 23:58
Oh yea i forgot to mention this script was written by ElfQuinn