What should I do if php cannot output images?

藏色散人
Release: 2023-03-08 19:58:02
Original
2142 people have browsed it

How to solve the problem that php cannot output pictures: first open the corresponding PHP code file; then add the "ob_clean()" function in the code and clear the output buffer to solve the problem of being unable to output pictures.

What should I do if php cannot output images?

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

PHP uses the GD2 library to draw pictures, and the image cannot be Output solution

Use PHP's GD2 library to draw images. When outputting on a browser, the image may not be output:

Add the ob_clean() function in the code and clear it. (erase) the output buffer.

The code is as follows:

<?php
    //用其他编辑器打开存储为utf-8 no bom
    ob_clean();/* 清空(擦掉)输出缓冲区,不加此行可能无法显示图像*/
$height=600;
$width=600;
//创建一个图像标识符
$im=imagecreatetruecolor($width,$height);
//为图像选择颜色
$white=imagecolorallocate($im,255,255,255);
$blue=imagecolorallocate($im,0,0,64);
$c=imagecolorallocate($im,255,125,10);
$red=imagecolorallocate($im,255,0,0);
//绘制背景颜色
imagefill($im,0,0,$blue);
//从左上角开始画一条线导图像右下角
imageline($im,0,0,$width,$height,$white);
//从左下角开始画一条线导图像右上角
imageline($im,600,0,0,600,$red);
//添加文字
imagestring($im,5,250,150,&#39;Hello World!&#39;,$c);
Header(&#39;Content-type:image/png&#39;);
imagepng($im);
imagedestroy($im);
?>
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What should I do if php cannot output images?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!