PHP image processing, PHP image processing _php Tutorial

Source: Internet
Author: User

PHP image processing, PHP image processing


PHP provides some functions for editing images, among which the most typical applications are random graphics verification codes, image watermarks, and the generation of pie and histogram in data statistics.

Some graphical functions in PHP can be used directly, but most need to be used after installing the GD2 function library. Installing the GD2 library under the Windows platform is simple, which is the Php_gd2_dll file in the Ext directory that PHP5 comes with.

If not, the GD2 library is not installed when you install PHP, open the php.ini file, view the php.ini file (c:\winsows), and see if there is a "; extension = Php_gd2.dll" in the file (Paths and Directories), if any, will be one of the ";" Remove, and then set the file extension directory Extension_dir value to the full path of PHP's ext directory, such as "Extension_dir = E:\php5\ext", Save and restart Apache

Drawing a graph typically consists of 4 steps: 1) Create a background, 2) draw a graphic or input text in the background, 3) output graphics, 4) Release all resources

Before this notice, the php.ini file in the Language options under the output_buffering default off to ON, and then restart Apache (Apache Restart), otherwise the following warning will appear:

Cannot modify header information-headers already sent by .....

Example: Drawing a PNG graphic, such as drawing a line

$image = imagecreate (400,400); // Create an image, two parameters represent the width and height of the image, in pixels, and return the data stream for this image $background _color = imagecolorallocate ($image, 255,255,255); // set a white background stream for the image, $black = imagecolorallocate ($image, 0,0,0); // set the black background stream for the image Imageline ($image, 0,0,100,100,$black); // draw a line and set its color to black Ob_clean (); // clear the output, otherwise the image cannot be displayed Header ("Content-type:image/png"); // Send header message to browser, output PNG image Imagepng ($image); // Output Graphics Imagedestroy ($image); // Clear Resources

Image processing function can directly create an image stream to draw graphics, you can also use the existing image as a stream of images, and then on the sub-basis of the image modification, such as adding watermark effect. This feature is often used to prevent images from being compromised.

Example: Adding a watermark URL to the original image (JPEG format)

    Ob_clean ();     Header ("Content-type:image/jpeg");     $im = imagecreatefromjpeg ("dog.jpg");     $red = imagecolorallocate ($im, 255,0,0);    Imagestring ($im, 5,6,10, "http://www.cnblogs.com/520xiuge/",$red);    Imagejpeg ($im);    Imagedestroy ($im);

http://www.bkjia.com/PHPjc/1131137.html www.bkjia.com true http://www.bkjia.com/PHPjc/1131137.html techarticle PHP image processing, PHP image processing PHP provides a number of images to edit the function of processing, the most typical application of random graphics verification code, image watermark and data statistics ...

  • 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.