Home >Backend Development >PHP Problem >How to solve the garbled problem of php imagecreate

How to solve the garbled problem of php imagecreate

藏色散人
藏色散人Original
2021-10-28 09:40:331997browse

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');" .

How to solve the garbled problem of php imagecreate

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:
How to solve the garbled problem of php imagecreate

Modified code:

<?php  
$im=imagecreate(200,200); 
//创建一个画布(单位像素pixel)
$white=imagecolorallocate($im,225,66,159); 
//设置画布的背景颜色为粉色 (256RGB)
header(&#39;content-type:image/gif&#39;);  
//设置gif 
Imageimagegif($im); 
//输出gif图像
imagedestroy($im); 
?>

Running results:
How to solve the garbled problem of php imagecreate 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn