PHP Add text watermark code to the picture _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.