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);?>
?