Dynamic Image Processing-php (34) and dynamic image processing php34
1 Use of GD library in PHP
PHP can not only generate HTML output, but also create and operate image files of different formats. PHP provides some built-in image information functions. You can also use the GD function library to create new images or process existing images. Currently, the GD2 Library supports JPEG, PNG, and WBMP formats. However, the GIF format is no longer supported.
• JPEG is a standard name for compression. It is usually used to store photos or images with rich colors and color layers. This format uses lossy compression.
• PNG is a portable network image that adopts lossless compression standards.
• WBMP is a file format specially designed for wireless communication devices. But it is not widely used.
2. Image Generation steps
To create an image in PHP, follow these steps:
1. Create a background image (also called a canvas). Subsequent operations are based on this background image.
2. Draw an image profile or input text on the background.
3. Output final image
4. release resources
<? Php // create a background image $ height = 200; $ width = 200; $ im = ImageCreateTrueColor ($ width, $ height ); // create a blank background $ white = ImageColorAllocate ($ im, 255,255,255); // set the drawing color $ blue = ImageColorAllocate ($ im, 0, 0, 64 ); imageFill ($ im, 0, 0, $ blue); // draw the background imageLine ($ im, 0, 0, $ width, $ height, $ white ); // draw the line imageString ($ im, 4, 50,150, 'sales', $ white); // Add the string header ('content-type: image/png '); imagePng ($ im); // output the image to imageDes in PNG format Troy ($ im);?>3. Canvas Management
Imagecreate-create a palette-Based Image