Adding watermarks to pictures is something that many websites do. The code below only supports adding text watermarks to pictures. It only supports English for now. If you want this program to support Chinese characters, just put $font= 'verdana.ttf'; It's OK to call a Chinese font.
php tutorial to add text watermark code to images
/*
Adding watermarks to pictures is something that many websites do. The following code only supports adding text watermarks to pictures. Currently, it only supports English. If you want this program to support Chinese characters, just $font='verdana. ttf';Call a Chinese font and it will be ok.
*/
?>$image=$_get[id];
$im=getimagesize($image);
//print_r($im);
//The following is the width and height of the read text
$font='verdana.ttf';//Font
$font_size = $im[0]/20;//Text size
$size=imagettfbbox($font_size,0,$font,'bKjia.c0m');//Text width and height
$textwidth = $size [4];//Get the width
$textheight = abs( $size [7] );//Get the height$pic_w=abs(($im[0]-$textwidth)/2);//The position where the text is stored width
$pic_h=abs(($im[1]-$textheight)/2);//The high position where text is storedswitch($im[2]) {
case 2:
case 1:
$im=imagecreatefromgif($image);
break;
$im=imagecreatefromjpeg($image);
case 3:
break;
$im=imagecreatefrompng($image);
break;
}
//$logo="2.png";//Trademark image
//$ing=getimagesize($logo);
//
// switch($ing[2]) //
//{
//case 1:
//$in=imagecreatefromgif($logo);
//break;
//
//case 2:
//$in=imagecreatefromjpeg($logo);
//break;
//
//case 3:
//$in=imagecreatefrompng($logo);
//break;
//}
//imagecopy($im,$in,200,3,0,0,'120','110');//Image merge
$te = imagecolorclosestalpha($im,255,255,255,60);//The last value is the greater the transparency, the more transparent it is
$str=iconv("gbk","utf-8","bKjia.c0m"); //Set the text content and encoding, it's very simple
imagettftext($im,$font_size,0,$pic_w,$pic_h,$te,'verdana.ttf',$str);header("content-type: image/jpeg");
imagejpeg($im);
http://www.bkjia.com/PHPjc/633046.html