After installing some third-party libraries, you can quickly use PHP to create and process images with graphics processing skills. In fact, you don't need a lot of geometry--because I flunked this course in high school and now I can use PHP to create images! You need to install the GD library before you use the basic image creation function. To use JPEG-related image creation functions, you also need to install jpeg-6b. You must also install T1lib when using Type 1 fonts 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. Ensure that the above 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, there will be an error in compiling, which can overwhelm you for a while. 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] The last execute make, make install complete configuration. Restart Apache, and run the Phpinfo () function to check that the new functionality is working properly, and then you can start. Depending on the version of the GD library installed, you may have the ability to create GIF or PNG images. The point is that if you have a gd-1.6 or an earlier version installed, you can process the GIF file, but not the PNG file, and if you install gd-1.6 or later, you can handle the PNG file but not the GIF file. Creating a simple image requires several functions. I will follow the steps to demonstrate the following. The output contains the file header for the MIME type of the image you created, in this case PNG. Header ("Content-type:image/png"); Use Imagecreate () to create a variable that holds a blank image. The 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 time, you need to fill it with some color. But first you need to use the imagecolorallocate () function to determine the name for each color according to the RGB value of the color. The format of the function is imagecolorallocate ([image], [red], [Green], [blue]]. If blue, should use: $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, the Imagefill () function is used for color padding, 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 the memory and defragment the system at the end: Imagepng ($NEWIMG); Imagedestroy ($NEWIMG); Your code should look like this: Header ("Content-type:image/png"); $NEWIMG = Imagecreate (250,250); $skyblue = Imagecolorallocate ($newImg, 136,193,255); Imagefill ($NEWIMG, 0,0, $skyblue); Imagepng ($NEWIMG); Imagedestroy ($NEWIMG);?> If you invoke the script skyblue.php and access it using your own browser, you will see a blue PNG image of 250*250 pixel. You can also use image creation functions to process images, such as thumbnails created for large images. Suppose you're going to make a thumbnail of a 35*35 pixel size for a picture. What you want to do is create a new 35*35 pixel size image, produce an image stream containing the original image content, and then change the size of the original image and place it in a new, blank image. The key function to achieve this is imagecopyresized (), and 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]); comments are below the code: * * Send file header so that the browser knows the file type/header ("Content-type:image/png"); /* Set Variable save new picture long width */$newWidth = 35; $newHeight = 35; /* Create blank new picture with given length and width//$newImg = Imagecreate ($newWidth, $newHeight); * * from the original large map to obtain data/$ORIGIMG = Imagecreatefrompng ("Test.png"); /* Copy the picture after changing the size. Use function Imagesx () and Imagesy to get the x and x dimensions of the original picture * * imagecopyresized ($NEWIMG, $ORIGIMG, 0,0,0,0, $newWidth, $newHeight, Imagesx ($ ORIGIMG), Imagesy ($ORIGIMG)); * * Create final picture and empty memory/imagepng ($NEWIMG); Imagedestroy ($NEWIMG);?> If you invoke the script resized.php and use the browser to access the file, you can see a thumbnail png picture of 35*35 pixels.
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.