Php adds a rectangle to the image and adds a watermark.

Source: Internet
Author: User
Php adds a rectangle under the image and adds a watermark & lt ;? Counts the actual number of English characters in a mix of Chinese characters. only valid for gb2312 Code functionstr_len ($ str) {$ length0; for ($ i0; $ I & lt; strlen ($ str ); $ I ++) {if (ord ($ str [$ I]) & gt; 0x80) $ I ++; $ length ++ ;} retur php adds a rectangle under the image and adds a watermark
 0x80) $ I ++; $ length ++;} return $ length ;}// image to be added as a watermark $ imagefile = "3.jpg "; // the text to be added $ str = "The photo was uploaded by GoDo ". date ("Y, m, d, H, I minute, s seconds"); // native functions cannot count real characters due to Chinese characters doping, the watermark text cannot be centered. // you have written a function statistics. if the mbstring library supports this function, you can use mb_strlen for $ len = str_len ($ str ); // if the source code is UTF-8 encoded and does not require character conversion, delete this line $ str = iconv ('gb2312', 'utf-8', $ str ); // Obtain the source image size $ size = getimagesize ($ imagefile); // The height of the bottom side rectangle $ bottom_height = 20; // The font size $ font_size = 10; $ im = imagecr Eatetruecolor ($ size [0], $ size [1] + $ bottom_height); // The background color of the bottom side rectangle. modify the last three RGB parameters to change the color $ bgcolor = imagecolorallocate ($ im, 100,120,100); // font color $ ftcolor = imagecolorallocate ($ im, 255,255,255); imagefill ($ im, $ bgcolor); // created from jpeg by default, if you create an image from another image, you can select the function $ jpeg = imagecreatefromjpeg ($ imagefile) based on the extension; imagecopy ($ im, $ jpeg, $ size [0], $ size [1]); $ start_x = ($ size [0]-$ len * $ font_size)/2; $ start_x = ($ start_x> 0? $ Start_x: 0); $ start_y = $ size [1] + $ font_size + ($ bottom_height-$ font_size)/2; // C:/windows/fonts/SIMHEI. TTF is a ttf font file. imagettftext ($ im, $ font_size, 0, $ start_x, $ start_y, $ ftcolor, "C:/windows/fonts/SIMHEI. TTF ", $ str); header (" Content-type: image/jpeg "); imagejpeg ($ im); imageclose ($ jpeg);?>

?

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.