Create and process image _php tutorials in PHP

Source: Internet
Author: User
After installing some third-party libraries, combined with graphics processing skills, you can quickly create and manipulate images using PHP. In fact, you don't need a lot of geometry-because when I was in high school I didn't pass the course and now I can use PHP to create images! Before using the basic image creation function, you need to install the GD library. To use JPEG-related image creation functions, you will also need to install jpeg-6b. You must also install T1lib when using the Type 1 font in the image. ASDF here, you will also need to make further adjustments to your system settings. First install T1lib and end, then jpeg-6b. The third step is to install the GD function library. Make sure that the three parts are installed sequentially because you need to compile the GD library to use the JPEG-6B library. If you install jpeg-6b first, the compilation will go wrong, which will leave you at a loss for some time. After the three function libraries, reconfigure PHP. This is a typical way to easily install the DSO version of PHP. Then execute make clean, command, and add the following code to the current configuration hint:--with-gd=[/path/to/gd]--with-jpeg-dir=[/path/to/jpeg-6b]--with-t1lib=[/path/ To/t1lib] Finally perform make, make install to complete the configuration. Restart Apache and run the Phpinfo () function to check if the new feature is functioning properly, and then you can start. Depending on the installed GD library version, you may have the ability to create GIF or PNG images. The point is that if you already have gd-1.6 or an earlier version, you can work with GIF files, but not PNG files, and if you have gd-1.6 or later, you can handle PNG files but not GIF files. Several functions are required to create a simple image. I will follow the steps shown below. The output contains the file header of the MIME type of the image you created, in this case PNG. Header ("Content-type:image/png"); Use Imagecreate () to create a variable to hold a blank image. This function requires a picture pixel size. The format is imagecreate (X_size, y_size), a picture of 250*250 pixels, as follows: $NEWIMG = Imagecreate (250,250); Because your image is still blank at this point, you need to fill it with some color. But first you need to use the imagecolorallocate () function to determine the name of each color by the RGB value of the color. The format of the function is imagecolorallocate ([image], [red], [green], [bLue]). If it is turquoise, it should be used: $skyblue = Imagecolorallocate ($newImg, 136,193,255); Next, use the Imagefill () function to fill the image with the above color. In fact, the Imagefill () function has multiple versions, such as Imagefillrectangle (), Imagefillpolygon (), and so on. For simplicity, color fills with the Imagefill () function in the following format: Imagefill ([Image], [Start x Point], [Start y point], [color]) Imagefill ($NEWIMG, 0,0,$ Skyblue); Finally, create the final image and destroy the image stream to free up memory and defragment the system after the end: Imagepng ($NEWIMG); Imagedestroy ($NEWIMG); Your code should look like this: If you call the script skyblue.php and use your browser to access it, you will see a blue PNG image of 250*250 pixels. You can also use image creation functions to manipulate images, such as thumbnails created for large images. Suppose you're going to make a thumbnail of 35*35 pixel size for a picture. All you have 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 a new, blank image. The key function to achieve this is imagecopyresized (), which is formatted 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]); Comments under Code Surface: If you call script resized.php and use a browser to access this file, you can see a thumbnail png image of 35*35 pixels.

http://www.bkjia.com/PHPjc/314218.html www.bkjia.com true http://www.bkjia.com/PHPjc/314218.html techarticle after installing some third-party libraries, combined with graphics processing skills, you can quickly create and manipulate images using PHP. In fact, you don't need a lot of geometry knowledge-because ...

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