Ubuntu under PHP using GD Library notes

Source: Internet
Author: User
Tags phpinfo

The first is to see if the GD Library is properly installed and loaded. Through Gd_info () can be seen, or phpinfo. In Phpinfo, you can see the GD column, and then if the version is bundled (2.0.34 compatible), it is bound from the php4.3. If not, you can install one with the command:
sudo apt-get install PHP5-GD. Or to install the full version, add two lines to the source list:
Deb Http://packages.dotdeb.org Stable All
DEB-SRC Http://packages.dotdeb.org Stable All
Then upgrade under: sudo apt-get update. Install the PHP5-GD again.

Online has said that after the installation is finished php.ini will be updated, but mine is not. Search gd.so in/usr/lib/php5/20060613+lfs/down, php.ini under/ETC/PHP5/APACH2. Then manually modify the php.ini. In which you modify extension_dir= "/usr/lib/php5/20060613+lfs/", and then add a row of extension=gd.so. Then restart APACH2:SUDO/ETC/INIT.D/APACH2 restart.

After this is done, you can write a test applet. I'm using an example from the PHP manual. The file name is pic.php.

1
2
3
4
5
6
7
8
9
<?php
Header ("Content-type:image/png");
$im = Imagecreatetruecolor (300, 200);
$BG _color= imagecolorallocate ($im, 0, 0, 0);
$text _color= imagecolorallocate ($im, 23, 14, 91);
Imagestring ($im, 1, 5, 5, "A simple Text String", $text _color);
Imagepng ($im);
Imagedestroy ($im);
?>

When you open in the browser, you start to experience some problems. The discovery prompts me to download the file, after downloading uses the Gvim to open discovers is garbled, but can see the PNG word, guess this should be the PNG image binary data, but did not be recognized by the browser. After comparing with UltraEdit and other PNG images, it was found that the PNG image header is the same, but the end is four more bytes. However, after renaming to Pic.png, you can open it with the image viewer.

Continue to search, finally in the Phpchina forum saw a lot of people ask this question. Found a plausible answer to the argument. Say that this PHP code is generating pictures, so do not output anything before PHP code, including spaces. Try it, sure enough. But you need to close the browser first, then open, otherwise the browser output is cached things. The src= "pic.php" is invoked in another file test.php with the SRC attribute of IMG, which is shown as normal. So I think, if you need to use the GD library to generate pictures, it is best to generate pictures of the file alone.

Finally tangled up, began to write verification code.

Ubuntu under PHP using GD Library notes

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.