Home  >  Article  >  Backend Development  >  How to solve the problem of garbled characters when outputting images to WeChat browser using gd library in PHP

How to solve the problem of garbled characters when outputting images to WeChat browser using gd library in PHP

WJ
WJOriginal
2020-06-09 17:04:103007browse

How to solve the problem of garbled characters when outputting images to WeChat browser using gd library in PHP

#How to solve the problem of garbled characters when using gd to output images to WeChat browser in PHP?

The procedure is as follows:

<?php
$im = imagecreate(200, 300);
$white = imagecolorallocate($im, 8, 2, 133);
imagegif($im);
 ?>

After entering the address of the PHP file in the browser, I found that the following garbled characters were displayed:

How to solve the problem of garbled characters when outputting images to WeChat browser using gd library in PHP

After After further study, I found that for images created with the GD library, you need to use the function header('content-type:image/gif'); to specify which format to output. If you don't specify it, it will be garbled. .

The modified code is as follows:

<?php
// header(&#39;content-type:image/gif&#39;);
$im = imagecreate(200, 300);
$white = imagecolorallocate($im, 8, 2, 133);
header(&#39;content-type:image/gif&#39;);
imagegif($im);
 ?>

The modified picture is displayed as follows:

How to solve the problem of garbled characters when outputting images to WeChat browser using gd library in PHP

Related recommendations: php Tutorial

The above is the detailed content of How to solve the problem of garbled characters when outputting images to WeChat browser using gd library in PHP. 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