 Edge Development
features:



Forums
Links
Post News
View Blogs
Active users in the last 5 mins
Registered Users:5017
There are currently 0 registered users and 6 guests browsing the website.
Welcome our latest member: nqetofs
A news back-end to implement into your website is Articals/RSS or SMS news XML/RSS.
|
Image watermark feature
@ :: code :: Feb 28 2003, 04:20 (UTC+0) | From: ElfQrin : This function adds a text into an image. 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: <IMG SRC="watermark.php?wmimg=image.jpg"> <IMG SRC="watermark.php?wmimg=image.jpg&wmtext=Hello%20World" BORDER=0 ALT="test image" TITLE="this is a test" ALIGN=LEFT> Create a file called watermark.php with this content:
// watermark by Elf Qrin ( http://www.ElfQrin.com/ ) function watermark($img,$text="[date]",$datfmt="Y-m-d",$font="ARIAL.TTF",$font_size=12,$rgbtext="FFFFFF",$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+$syp,$coltsdw,$font,$text); ImageTTFText($image,$font_size,0,$txp,$typ,$coltext,$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,$wmtyp,$wmsxp,$wmsyp); }
Sample HTML page:
<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>
|
|
|
|
| | | | | | 1 | | 2 | 3 | 4 | 5 | 6 | 7 | 8 | | 9 | 10 | 11 | 12 | 13 | 14 | 15 | | 16 | 17 | 18 | 19 | 20 | 21 | 22 | | 23 | 24 | 25 | 26 | 27 | 28 | 29 | | 30 | 31 | | | | | |
: None
Aug 17, 2005
 martin-323x264-261x172.jpg / :: Random :: | "The only element in the Universe more plentiful than Hydrogen is stupidity." Albert Einstein
based on the number of submissions for the last 30 days
|
User |
Number of news items posted |
| Jul 14, 17:08 |
| Sep 19, 15:29 |
| Aug 30, 20:33 |
| Nov 15, 22:46 |
| Nov 15, 22:38 |
|