An error occurred while drawing the text program in PHP. how can this problem be solved?
Source: Internet
Author: User
An error occurred while drawing the PHP text program. The code for solving the problem is as follows: & lt ;? Php & nbsp; $ im = imagecreatetruecolor (255,255,255, 30); $ white = imagecolorallocate ($ im,); $ gray = imagecolor PHP: An error occurred while plotting the text program.
The program code is as follows:
$ Im = imagecreatetruecolor (400,30 );
$ White = imagecolorallocate ($ im, 255,255,255 );
$ Gray = imagecolorallocate ($ im, 128,128,128 );
$ Black = imagecolorallocate ($ im, 0, 0 );
Imagefilledrectangle ($ im, 0,0, 399,29, $ white );
$ Text = iconv ("GB2312", "UTF-8", "PHP draw text program"); // if there is a Chinese output, you need to transcode it, the string converted to the UTF-8 can be passed directly
$ Font = 'simsun. ttc ';
Imagettftext ($ im, 20, 0, 12, 21, $ gray, $ font, $ text); // output a gray string as the Shadow
Imagettftext ($ im, 20, 0, 10, 20, $ black, $ font, $ text); // output a black string on the shadow.
Header ('content-type: image/png ');
Imagepng ($ im );
Imagedestroy ($ im );
?>
The browser displays the following:
What's wrong with this?
------ Solution --------------------
Didn't he tell you clearly that the font file couldn't be found?
$ Font = 'simsun. ttc '; // Copy simsun. ttc to the current directory.
Test writing
$ Font = 'C:/windws/fonts/simsun. ttc ';
You can.
------ Solution --------------------
The fonts folder is different from other folders. you can see the font name and not the file name. you can see it only when you view the attributes.
Simsun. ttc is &
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