Add watermark to the picture is a lot of web site will do things, the following code only supports the text watermark Oh, now only support English, if you want this program to support Chinese characters will $font=\ ' verdana.ttf\ '; Calling a Chinese font is OK.
PHP Tutorial to add text watermark code to a picture
/*
Add watermark to the picture is a lot of web site will do things, the following code only supports the text watermark Oh, now only support English, if you want this program to support Chinese characters will $font= ' Verdana.ttf '; Calling a Chinese font is 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 high
$textwidth = $size [4];//out wide
$textheight = ABS ($size [7]);//Remove High
$pic _w=abs (($im [0]-$textwidth)/2);//text store wide position
$pic _h=abs (($im [1]-$textheight)/2);//The position where the text is stored high
Switch ($im [2])
{
Case 1:
$im =imagecreatefromgif ($image);
Break
Case 2:
$im =imagecreatefromjpeg ($image);
Break
Case 3:
$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 ');//Picture merge
$te = Imagecolorclosestalpha ($im, 255,255,255,60);//The last value is the greater the transparency the more transparent
$str =iconv ("GBK", "Utf-8", "bkjia.c0m"); It's easy to set the text content and code.
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 www.bkjia.com true http://www.bkjia.com/PHPjc/633046.html techarticle to the picture watermark is a lot of web site will do things, the following code is only supported for the picture with text watermark Oh, now only support English, if you want to let this program can support Chinese Han ...