Create and process images in PHP

Source: Internet
Author: User
PHP creates and processes images after some third-party function libraries are installed, you can quickly use PHP to create and process images with graphic processing skills. In fact, you don't need a lot of geometric knowledge-because I used to fail this course when I was in middle school, but now I can use PHP to create images! Install the GD library before using basic image creation functions. To create a function using JPEG-related images, you also need to install the jpeg-6b. T1lib must also be installed when Type 1 is used in the image. Here, you also need to make further adjustments to your system settings. First install t1lib and end, then the jpeg-6b. Step 3 install the GD function library. Make sure that the above three parts are installed in order because you need to compile the GD library before using the jpeg-6b Library. If you install the jpeg-6b first, compilation will go wrong, which will make you overwhelmed for a while. After the three function libraries, reconfigure PHP. This is a typical method for easily installing the DSO version of PHP. Run the make clean command and add the following code to the current configuration prompt: -- with-gd = [/path/to/gd] -- with-jpeg-dir = [/path/to/jpeg-6b] -- with-t1lib = [/path/to/t1lib] last run make and make install to complete the configuration. Restart Apache and run the phpinfo () function to check whether the new function runs properly. then you can start. Depending on the installed GD Library version, you may be able to create GIF or PNG images. The key is that if you have installed a gd-1.6 or an earlier version, you can process GIF files, but not PNG files; if you have installed a gd-1.6 or a later version, you can process PNG files but not GIF files. Several functions are required to create a simple image. I will demonstrate it as follows. The output contains the file header of the MIME type of the image you created. PNG is used in this example. Header ("Content-type: image/png"); use ImageCreate () to create a variable to store blank images. This function requires an image pixel size. The format is ImageCreate (x_size, y_size). For images of 250*250 pixels, see: $ newImg = ImageCreate (250,250). because your image is still blank, so you need to fill it with some colors. However, you must first use the ImageColorAllocate () function to determine the name of each color based on the RGB value of the color. The function format is ImageColorAllocate ([image], [red], [green], [blue]). If the sky is blue, use $ skyblue = ImageColorAllocate ($ newImg, 136,193,255). Then, use the ImageFill () function to fill the image with the above colors. In fact, the ImageFill () function has multiple versions, such as ImageFillRectangle () and ImageFillPolygon. For simplicity, use the ImageFill () function for color filling. the format is as follows: ImageFill ([image], [start x point], [start y point], [color]) imageFill ($ newImg, $ skyblue); finally, create the final image and destroy the image stream to release the memory and then organize the system: ImagePNG ($ newImg ); imageDestroy ($ newImg); your code should look like this: If you call the script skyblue. php to access it with your browser, you will see a 250*250 pixel blue PNG image. You can also use the image creation function to process images, such as thumbnails for large images. Suppose you want to create a 35*35 pixel thumbnail for an image. All you need to do is create a new 35*35 pixel size image, and generate an image stream containing the original image content. then, change the size of the original image, and place it in the new blank image. The key function to achieve this goal is ImageCopyResized (). The format is as follows: ImageCopyResized ([new image handle], [original image handle], [new image X], [new Image Y], [original image X], [original image Y], [new image X], [new image Y], [original image X], [original image Y]); comment in the code below: If you call the script resized. php and use a browser to access this file, you can see a 35*35 pixel thumbnail PNG image.

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.