Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that imagepng cannot be displayed in php

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will introduce in detail for you "how to solve the problem that imagepng can not display in php", the content steps are clear and detailed, the details are handled properly, and the editor updates different knowledge points every day, I hope this article "how to solve the problem that imagepng can not display in php" can give you unexpected gains, please follow the editor's ideas slowly in depth, the specific contents are as follows, to harvest new knowledge together.

Php imagepng can not display the solution: 1, use third-party coding tools to save the file format without BOM utf-8 format; 2, use "ob_clean ();" to clear the buffer.

This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer

PHP uses GD library to draw images and can't display them.

Draw image document styles according to the official GD library

Original basic style:

@ imagecreatetruecolor ($width, $height) or die ('Cannot Initialize new GD image stream'); / / create a new GD image resource $img_bgcolor = imagecolorallocate ($img, mt_rand (157255), mt_rand (157255), mt_rand (157255)); / / background color $img_textcolor = imagecolorallocate ($img, mt_rand (0255), mt_rand (0255), mt_rand (0255)); / / font color $img_rectangle = imagefilledrectangle ($img,0,0,$width, $height,$img_bgcolor) / draw a rectangular image imagestring ($img, 1,5,5,'A Simple Text String', $img_textcolor); / / output image header ("Content-type:image/png"); imagepng ($img); imagedestroy ($img); / / destroy the image

However, in practical application, there will be the problem that the image can not be displayed properly:

There may be several reasons for this:

Reason 1: file encoding format with BOM header, solution, use third-party coding tools, sublime or notepad++ to save the file format to BOM-free utf-8 format

The cause of the 2:PHP buffer problem, the solution is to use ob_clean (); empty the buffer.

Common buffer function ob function

Reference: http://php.net/manual/zh/ref.outcontrol.php

Ob_get_contents ()-returns the contents of the output buffer

Ob_flush ()-flushes the contents of the output buffer

Ob_clean ()-clear (erase) the output buffer

Ob_end_flush ()-flushes out (sends out) the contents of the output buffer and turns off buffering

Ob_end_clean ()-clear (erase) the buffer and turn off the output buffer

Flush ()-refresh the output buffer

Determine whether the GD library is installed

Function_exists ('imagecreate') judges get_extension_funcs () by judging whether the method provided by the extension library exists, but it is not comprehensive and is not recommended (because some extensions do not provide functions)

In_array ('extension', get_loaded_extensions ()) determines whether the extension is installed by verifying that the extension is in the loaded extension (comprehensive, but not concise)

Extension_loade ('extension library name') verifies by determining whether the extension library is loaded (comprehensive and not concise, it is recommended to use this method to verify whether the extension is loaded)

What are the PHP development environment building tools? phpStudy is the most commonly used development environment for beginners. Second, WampServer,WampServer is also as simple as phpStudy and more friendly to rookies. Third, XAMPP,XAMPP (Apache+MySQL+PHP+PERL) is a powerful integrated software package for building stations; fourth, MAMP,MAMP is divided into two types: MAMP and MAMP Pro for Mac. Pagoda panel, pagoda panel is a server management software that supports windows and linux systems. 6. UPUPW,UPUPW is the most characteristic Web server PHP suite under the Windows platform.

Thank you for reading this. I hope you have the most profound experience from the practical level on the key issue of "how to solve the problems that cannot be displayed by imagepng in php". If you want to read more related articles, you are welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report