Solution to the problem that php cannot display pictures: 1. Remove the semicolon before "extension=php_gd2.dll" in the "php.ini" file; 2. Set "extension_dir" correctly; 3. Put the file Save in "utf8 no bom" format.
Recommended: "PHP Tutorial"
PHP dynamically generated pictures cannot be displayed
Test code:
<?php header("Content-type: image/png"); $im = @imagecreate(200, 30) or die("无法连接GD库!"); $background_color = imagecolorallocate($im, 255, 255, 255); $text_color = imagecolorallocate($im, 233, 14, 91); imagestring($im, 5, 5, 5, "A Simple Text String", $text_color); imagepng($im); imagedestroy($im); ?>
If the picture cannot be displayed, it may be the following problem:
1. The semicolon before the code extension=php_gd2.dll in the php.ini file Not removed.
2. extension_dir is not set correctly. The correct setting should be like this: extension_dir = "E:/Project/Web/php5.3/ext"
3. Regarding file encoding, the file should be saved in utf8 no bom format. Here is some information about bom. Explanation:
----------------Note-----------------------
UTF-8 encoded files can be divided into two formats: no BOM and BOM
What is BOM? The three bytes "EF BB BF" are called BOM, and the full name of BOM is "Byte Order" Mard". BOM is commonly used in UTF-8 files to indicate that the file is a UTF-8 file, and the original meaning of BOM is used to represent high and low byte sequences in UTF16.
There is a BOM before the byte stream, which means that the low byte sequence is used (the low byte is in front), and utf8 does not need to consider the byte sequence, so in fact, it can be used with or without BOM.
Microsoft Notepad, Word, etc. can only correctly open UTF8 files containing BOM, but UltraEdit does the opposite, mistaking BOMutf8 files for ascii encoding.
The problem is finally solved, I am happy... ....
The above is the detailed content of What should I do if php cannot display images?. For more information, please follow other related articles on the PHP Chinese website!