Creating images using the GD2 Library in php cannot be displayed in the browser

Source: Internet
Author: User
Using the GD2 Library in php to create images cannot be displayed in the browser. I just learned PHP and cannot display images in the browser when using the GD2 library to create images, there is only one icon that represents the image. my code is as follows:
Header ("content-type: image/gif ");
$ Image = imagecreate (, 80 );
$ Bg = imagecolorallocate ($ image, 220, 40,120 );
Imagegif ($ image );
?>
It should be okay. In addition, my BOM header is removed, but it cannot be displayed. thank you for your guidance! Thank you!


Reply to discussion (solution)

The code is okay. Check your environment. Enable the error prompt function.

Well, it should be an environment setup problem! Download a wamp and enable the gd2 extension!

The code is okay. Check your environment. Enable the error prompt function.


The error prompt function is enabled:
; Display_errors
; Default Value: On
; Error_reporting
; Default Value: E_ALL &~ E_NOTICE
After the code is run, there is no error prompt in the browser, and there is no image to display, but a flag indicating the image is displayed in the upper left corner.

Well, it should be an environment setup problem! Download a wamp and enable the gd2 extension!


I just downloaded the wamp, and the php. ini file shows: extension = php_gd2.dll. The GD2 Library has been enabled, but it cannot be done. please advise.

You can use the same environment and code on other computers.

Why can't I use my computer?

My phpinfo () function shows that the GD Library is enabled:
Gd

GD Support enabled
GD Version bundled (2.0.34 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.4.6
T1Lib Support enabled
GIF Read Support enabled
GIF Create Support enabled
JPEG Support enabled
LibJPEG Version 6b
PNG Support enabled
LibPNG Version 1.2.46
WBMP Support enabled
XBM Support enabled

Directive Local Value Master Value
Gd.jpeg _ ignore_warning 0 0
Why is it useless? for help!

After trying out the code, you can-(only display a sign indicating the image in the upper left corner) change the browser to see it...

It's useless to change the browser, or the image cannot be displayed, and
If (! Function_exists ("imagecreat "))
Echo "GD support is not installed ";
Else
If (! Function_exists ("imagecreattruecolor "))
Echo "GD2 is installed ";
?> After this code is executed, the output "GD support is not installed", but my phpinfo () shows that there is a GD Library. why?

In fact, the GD library is not running normally. use another PHP version.

It's useless to change the browser, or the image cannot be displayed, and
If (! Function_exists ("imagecreat "))
Echo "GD support is not installed ";
Else
If (! Function_exists ("imagecreattruecolor "))
Echo "GD2 is installed ";
?> After this code is executed, the output "GD support is not installed" is displayed, but my phpinfo () shows that there is ......

For PHP ...? Is there a simpler way... I installed wamp. if you want to change it, you have to change it all. please advise.

My problem has been solved. thank you. I used to have html tags in my code. just remove them.

Why can't I remove HTML tags if I encounter the same problem as you do.

Why can't I remove HTML tags if I encounter the same problem as you do.


Well, there is indeed no HTML. I only have a small problem with code. Haha.

Why can't I remove HTML tags if I encounter the same problem as you do.


How did you solve it?

Clear the cache before the drawing (that is, before writing the header), first write ob_clean (); then you can display
Detailed source reference: http://www.jb51.net/article/47673.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.