Creating a display IP image You need to install the GD library file before using the basic image creation function. If you want to create a function related to JPEG, you will need to install JPEG-6B. If you want to use the Type 1 type font in the image, you must install T1LIB.
Before establishing an image creation environment, you need some preparations. First, install T1LIB then install JPEG-6B, then install the GD library file. Be sure to install in the order here, because JPEG-6B is used when compiling GD storage, if JPEG-6B is installed, it will be wrong when compiling.
After installing these three components, you also need to reconfigure PHP, which is one of you who is fortunate to install PHP in DSO. Run Make Clean, then add the following content in the current configuration:
--with-gd = [/ path / to / gd] --with-jpeg-dir = [/ path / to / jpeg-6b] --with-t1lib = [/ patH / to / t1lib]
After completing the addition, execute the make command, then execute the make install command, then restart the apache and run PHPINFO () to check if the new settings have taken effect. Now we can start image creation work.
Depending on the version of the installed GD library file, you will decide if you can create graphics files in GIF or PNG format. If you installed GD-1.6 or previous versions, you can use the GIF format file but cannot create a PNG format. If you installed the GD-1.6 later version, you can create a PNG file but cannot create a file file.
Creating a simple image also requires many functions, we will explain step by step.
In the following example, we will create an image file in a PNG format. The following code is a header of the MIME type of the image created:
Header ("Content-Type: Image / PNG");
Create a variable representing a blank image using ImageCreate (), which requires parameters of image size in pixels, which is imagecreate (x_size, y_size). If you want to create an image of 250 × 250, you can use the following statement:
$ newimg = imagecreate (250, 250);
Since the image is still blank, you may want to use some colors to fill it. You need to first specify a name for this color using the imagecolaocate () function to use its RGB value, this function is imagecolorallocate ([Image], [Red], [Green], [Blue]). If you want to define the sky, you can use the following statement:
$ skyblue = imagecolorallocate ($ NEWIMG, 136, 193, 255);
Next, you need to use the imagefill () function to populate this image with this color, and the imagefill () function has several versions, such as ImageFillRectangle (), ImageFillPolygon (), and so on. For simplicity, we use imagefill () functions through the following format:
ImageFill ([Image], [Start X Point], [Start Y Point], [Color]) ImageFill ($ Newimg, 0,0, $ SkyBlue);
Finally, release the image handle and the memory you occupied after the image: imagepng ($ newimg); ImageDestroy;?>>
In this way, all code to create images are as follows:
?
If this script file is saved as SkyBlue.php, use a browser to access it, we will see an image of a sky blue 250 × 250 PNG format.
We can also use image creation functions to process images, such as making a large image into a small image:
Suppose you have an image, you want to cut out a 35 × 35 size image from it. What you need is to create a blank image of a 35 × 35 size, create an image stream containing the original image, and then put a resized original image in a new blank image.
The key function to complete this task is imageCopyResized (), which requires the format as follows:
ImageCopyResize, [Original Image Handle], [NEW Image Y], [NEW Image Y], [Original Image Y], [NEW Image X], [New Image Y], [Original Image X], [Original Image Y]. / * Send a head so that the browser knows the content type * / header ("content-type: image / png") included in the file; / * Establish a variable for saving new image height and width * / $ NewWidth = 35; $ newHeight = 35; / * Creating a new blank image for a given height and width * / $ newimg = imagecreate ($ newwidth, $ newheight); / * Get data from the original image * / $ Origimg = ImageCreateFromNG ("Test.png"); / * Copy the image after adjustment, use imageSx (), imageeeSy () Get the original image in x, y, * / imageCopyResized ($ newimg, $ Origimg, 0,0,0,0,0,0,0,0,0, $ newwidth, $ newheight, imagesx ($ Origimg), ImageeSy ($ Origimg)); / * Create a desired image, release memory * / imagepng ($ newimg); ImageDestroy ($ newimg) ;?>
If you save this small script as resized.php, then use the browser to access it, you will see an image of a 35 × 35 size PNG format. Reprinted to my space Copy This website requires the GD library file before using the basic image creation function. If you want to create a function related to JPEG, you will need to install JPEG-6B. If you want to use the Type 1 type font in the image, you must install T1LIB. Before establishing an image creation environment, you need some preparations. First, install T1LIB then install JPEG-6B, then install the GD library file. Be sure to install in the order here, because JPEG-6B is used when compiling GD storage, if JPEG-6B is installed, it will be wrong when compiling.
After installing these three components, you also need to reconfigure PHP, which is one of you who is fortunate to install PHP in DSO. Run Make Clean, then add the following content in the current configuration:
--with-gd = [/ path / to / gd] --with-jpeg-dir = [/ path / to / jpeg-6b] --with-t1lib = [/ patH / to / t1lib]
After completing the addition, execute the make command, then execute the make install command, then restart the apache and run PHPINFO () to check if the new settings have taken effect. Now we can start image creation work.
Depending on the version of the installed GD library file, you will decide if you can create graphics files in GIF or PNG format. If you installed GD-1.6 or previous versions, you can use the GIF format file but cannot create a PNG format. If you installed the GD-1.6 later version, you can create a PNG file but cannot create a file file.
Creating a simple image also requires many functions, we will explain step by step.
In the following example, we will create an image file in a PNG format. The following code is a header of the MIME type of the image created:
Header ("Content-Type: Image / PNG");
Create a variable representing a blank image using ImageCreate (), which requires parameters of image size in pixels, which is imagecreate (x_size, y_size). If you want to create an image of 250 × 250, you can use the following statement:
$ newimg = imagecreate (250, 250);
Since the image is still blank, you may want to use some colors to fill it. You need to first specify a name for this color using the imagecolaocate () function to use its RGB value, this function is imagecolorallocate ([Image], [Red], [Green], [Blue]). If you want to define the sky, you can use the following statement:
$ skyblue = imagecolorallocate ($ NEWIMG, 136, 193, 255);
Next, you need to use the imagefill () function to populate this image with this color, and the imagefill () function has several versions, such as ImageFillRectangle (), ImageFillPolygon (), and so on. For simplicity, we use imagefill () functions through the following format:
ImageFill ([Image], [Start X Point], [Start Y Point], [Color]) ImageFill ($ NEWIMG, 0, 0, $ SKYBLUE); Finally, release the image handle and the memory occupied after the image is established:
ImagePNG ($ newimg); ImageDestroy ($ newimg);?>
In this way, all code to create images are as follows:
?
If this script file is saved as SkyBlue.php, use a browser to access it, we will see an image of a sky blue 250 × 250 PNG format.
We can also use image creation functions to process images, such as making a large image into a small image:
Suppose you have an image, you want to cut out a 35 × 35 size image from it. What you need is to create a blank image of a 35 × 35 size, create an image stream containing the original image, and then put a resized original image in a new blank image.
The key function to complete this task is imageCopyResized (), which requires the format as follows:
ImageCopyResize, [Original Image Handle], [NEW Image Y], [NEW Image Y], [Original Image Y], [NEW Image X], [New Image Y], [Original Image X], [Original Image Y]. / * Send a head so that the browser knows the content type * / header ("content-type: image / png") included in the file; / * Establish a variable for saving new image height and width * / $ NewWidth = 35; $ newHeight = 35; / * Creating a new blank image for a given height and width * / $ newimg = imagecreate ($ newwidth, $ newheight); / * Get data from the original image * / $ Origimg = ImageCreateFromNG ("Test.png"); / * Copy the image after adjustment, use imageSx (), imageeeSy () Get the original image in x, y, * / imageCopyResized ($ newimg, $ Origimg, 0,0,0,0,0,0,0,0,0, $ newwidth, $ newheight, imagesx ($ Origimg), ImageeSy ($ Origimg)); / * Create a desired image, release memory * / imagepng ($ newimg); ImageDestroy ($ newimg) If you saved this small script as resize.php, you will see an image of a 35 × 35 size PNG format with a browser. You need to install the GD library file before using the basic image creation function. If you want to create a function related to JPEG, you will need to install JPEG-6B. If you want to use the Type 1 type font in the image, you must install T1LIB.
Before establishing an image creation environment, you need some preparations. First, install T1LIB then install JPEG-6B, then install the GD library file. Be sure to install in the order here, because JPEG-6B is used when compiling GD storage, if JPEG-6B is installed, it will be wrong when compiling.
After installing these three components, you also need to reconfigure PHP, which is one of you who is fortunate to install PHP in DSO. Run Make Clean, then add the following content in the current configuration:
--with-gd = [/ path / to / gd] --with-jpeg-dir = [/ path / to / jpeg-6b] --with-t1lib = [/ patH / to / t1lib]
After completing the addition, execute the make command, then execute the make install command, then restart the apache and run PHPINFO () to check if the new settings have taken effect. Now we can start image creation work.
Depending on the version of the installed GD library file, you will decide if you can create graphics files in GIF or PNG format. If you installed GD-1.6 or previous versions, you can use the GIF format file but cannot create a PNG format. If you installed the GD-1.6 later version, you can create a PNG file but cannot create a file file. Creating a simple image also requires many functions, we will explain step by step.
In the following example, we will create an image file in a PNG format. The following code is a header of the MIME type of the image created:
Header ("Content-Type: Image / PNG");
Create a variable representing a blank image using ImageCreate (), which requires parameters of image size in pixels, which is imagecreate (x_size, y_size). If you want to create an image of 250 × 250, you can use the following statement:
$ newimg = imagecreate (250, 250);
Since the image is still blank, you may want to use some colors to fill it. You need to first specify a name for this color using the imagecolaocate () function to use its RGB value, this function is imagecolorallocate ([Image], [Red], [Green], [Blue]). If you want to define the sky, you can use the following statement:
$ skyblue = imagecolorallocate ($ NEWIMG, 136, 193, 255);
Next, you need to use the imagefill () function to populate this image with this color, and the imagefill () function has several versions, such as ImageFillRectangle (), ImageFillPolygon (), and so on. For simplicity, we use imagefill () functions through the following format:
ImageFill ([Image], [Start X Point], [Start Y Point], [Color]) ImageFill ($ Newimg, 0,0, $ SkyBlue);
Finally, release the image handle and the memory occupied after the image is established:
ImagePNG ($ newimg); ImageDestroy ($ newimg);?>
In this way, all code to create images are as follows:
?
If this script file is saved as SkyBlue.php, use a browser to access it, we will see an image of a sky blue 250 × 250 PNG format.
We can also use image creation functions to process images, such as making a large image into a small image:
Suppose you have an image, you want to cut out a 35 × 35 size image from it. What you need is to create a blank image of a 35 × 35 size, create an image stream containing the original image, and then put a resized original image in a new blank image.
The key function to complete this task is imagecopyresize (), which requires the format as follows: ImageCopyResize, [Original Image Handle], [NEW Image Y], [New Image Y], [Original Image X], [Original Image Y], [New Image Y], [NEW Image Y], [Original Image Y]. / * Send a head so that the browser knows the content type * / header ("content-type: image / png") included in the file; / * Establish a variable for saving new image height and width * / $ NewWidth = 35; $ newHeight = 35; / * Creating a new blank image for a given height and width * / $ newimg = imagecreate ($ newwidth, $ newheight); / * Get data from the original image * / $ Origimg = ImageCreateFromNG ("Test.png"); / * Copy the image after adjustment, use imageSx (), imageeeSy () Get the original image in x, y, * / imageCopyResized ($ newimg, $ Origimg, 0,0,0,0,0,0,0,0,0, $ newwidth, $ newheight, imagesx ($ Origimg), ImageeSy ($ Origimg));
/ * Create a desired image, release memory * / imagepng ($ newimg); ImageDestroy;?>>
If you save this small script as resized.php, then use the browser to access it, you will see an image of a 35 × 35 size PNG format.