php imagecreate garbled solution: 1. Create a canvas through imagecreate; 2. Use imagecolorallocate to set the background color of the canvas; 3. Set "header('content-type:image/gif');" .
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
How to solve the garbled problem of php imagecreate?
Solution to the problem that PHP becomes garbled when creating an image (GD)
Problematic code:
nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <meta> <title>php学习</title> <?php $im=imagecreate(200,200); //创建一个画布(单位像素pixel) $white=imagecolorallocate($im,225,66,159); //设置画布的背景颜色为粉色 (256RGB) imagegif($im); //输出gif图像 imagedestroy($im); ?>
Running result:
Modified code:
<?php $im=imagecreate(200,200); //创建一个画布(单位像素pixel) $white=imagecolorallocate($im,225,66,159); //设置画布的背景颜色为粉色 (256RGB) header('content-type:image/gif'); //设置gif Imageimagegif($im); //输出gif图像 imagedestroy($im); ?>
Running results:
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to solve the garbled problem of php imagecreate. For more information, please follow other related articles on the PHP Chinese website!