After installing some third-party libraries, with your graphics processing skills, you can create and process images in PHP. In fact, you don't need too much geometrical knowledge. When I was in high school, this course always failed, and now I will use PHP to create images!
You need to install the GD library before using the basic image creation function. If you want to use a JPEG-related image creation function You will also need to install jpeg-6b. You must also install T1lib when using Type 1 fonts in the image.
Here you will also need to make further adjustments to your system. First, you must install T1lib to provide image processing support, and then install JPEG-6B. The third step is to install the GD function library. You have to finish the three work in order, because you need to compile the GD library to use the JPEG-6B library, if the jpeg-6b step first installation, the compiler will be wrong, then you are busy around the round and there is no way.
After installing the above three function libraries, you will have to reconfigure PHP. This is what you do when you install the DSO version of PHP. Then execute make clean, command, and then add the following code to the current configuration instruction character:
The final order executes the make, make install command to complete the compounding task. Restart Apache and run the Phpinfo () function to check whether the new feature is working properly.
With your installation of the GD library, you might or may not have the ability to create GIF or PNG images. The point is: if you have a gd-1.6 or an earlier version installed, you can handle GIF but not PNG. If gd-1.6 or later versions are installed, you can handle PNG but not GIF.
Creating a simple image requires several functions. I will follow the steps to take you to learn this process:
Output a file header that contains the MIME type of the image you created, in our case PNG.
? Header ("Content-type:image/png");
Use Imagecreate () to create a variable that holds a blank image. The function requires an image size in pixels. The format is imagecreate (X_size, Y_size), and for 250-x-250 pixel images, the usage is as follows:
$NEWIMG = Imagecreate (250,250);
Because your image is still blank, you try to fill it with some color, but first you need to assign a name to each color according to the RGB value of the color, using the Imagecolorallocate () function. The format of the function is imagecolorallocate ([image], [red], [green], [blue]). If it is sky-blue, the specific code is as follows:
Next, you need to call the Imagefill () function to fill the color above the image. Imagefill (), there are several versions of the function, such as Imagefillrectangle (), Imagefillpolygon (), and so on. For simplicity, we use the Imagefill () function for color filling, in the following format:
Imagefill ([Image], [Start x Point], [Start y point], [color])
Imagefill ($NEWIMG, 0,0, $skyblue);
Finally, you create the image and destroy the image stream to free up memory:
Imagepng ($NEWIMG);
Imagedestroy ($NEWIMG);?>
The specific code looks something like the following:
If you call this script skyblue.php and use your own browser to access it, you will see a 250-x-250 pixel large blue png image.
You can also use image creation functions to process images, such as creating thumbnails of large images, and so on.
Suppose you're going to make a thumbnail of a 35-x-35 pixel size for a picture. You do this by creating a new X 35 pixel size image, creating an image stream containing its original image content, and then changing the size of the original image and putting it in a new, blank image.
The key function used to achieve the above is imagecopyresized (), which has the following format: 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], [Origin Al image Y]);
The following is a code comment.
? * Send a header so that the browser knows the Content-type of the file * * *
Header ("Content-type:image/png");
/* Set up variables to hold the height and width of your new image * *
$newWidth = 35;
$newHeight = 35;
/* Create a blank, new image of the given new height and width * *
$NEWIMG = Imagecreate ($newWidth, $newHeight);
/* Get the data from the original, large image * *
$ORIGIMG = Imagecreatefrompng ("Test.png");
/* Copy the resized image. Use the Imagesx () and Imagesy functions to get the X and y sizes of the orginal image. */
Imagecopyresized ($NEWIMG, $ORIGIMG, 0,0,0,0, $newWidth, $newHeight, Imagesx ($ORIGIMG), Imagesy ($ORIGIMG));
/* Create final image and free up the memory * *
Imagepng ($NEWIMG);
Imagedestroy ($NEWIMG);?>
If you call the above script resized.php and use your own browser to access it, you should be able to see a 35-x-35 pixel size of a thumbnail png.
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.