PHP image processing tutorial (1/3) _ PHP Tutorial

Source: Internet
Author: User
PHP image processing tutorial (13 ). PHP image processing Getting Started Tutorial This php image generation tutorial is a php Tutorial from generating a simple image to generating a complex image, in a simple way, there are 12 image generation instances. PHP image processing Getting Started Tutorial This php image generation tutorial is a php Tutorial from generating a simple image to generating a complex image, in a simple way, there are 12 image generation instances. 1. generate a simple image.

Php Tutorial image and graphics processing tutorial
This php image generation tutorial is a php Tutorial from generating a simple image to generating a complex image. There are 12 simple examples of generating images.

1. generate a simple image.
2. set the image color.
3. draw a straight line on the image.
4. display text on the image.
5. display Chinese characters in the image.
6. open an existing image.
7. obtain Image attributes.
The usage of the 8 function getimagesize.
9. add the watermark effect to the uploaded image.
10. generate a thumbnail of an existing image.
11 Use the imagecopyresampled () function ().
12. php program that generates a digital verification code image with a bottom line.

*/

// 1 generate a simple image.

$ Width = 200;
$ Height = 200;

$ Img = imagecreatetruecolor ($ width, $ height) or die ("gd image processing not supported ");
Imagepng ($ img );
Imagedestroy ($ img );

// 2 set the image color.

$ Width = 200;
$ Height = 200;

$ Img = imagecreatetruecolor ($ width, $ height) or die ("gd image processing not supported ");

$ Bg_color = imagecolorallocate ($ img, 255, 0, 0 );
Imagefill ($ img, 0, 0, $ bg_color );

Imagepng ($ img );
Imagedestroy ($ img );

// 3 Draw a straight line on the image.

$ Width = 200;
$ Height = 300;

$ Img = imagecreatetruecolor ($ width, $ height) or die ("gd image processing not supported ");

$ Line_color = imagecolorallocate ($ img, 255,255,255 );
Imageline ($ img, $ line_color );
Imageline ($ img, 0,260,200,260, $ line_color );

Imagepng ($ img );
Imagedestroy ($ img );

// 4. display text on the image.

$ Width = 200;
$ Height = 300;

$ Img = imagecreatetruecolor ($ width, $ height) or die ("gd image processing not supported ");
$ Line_color = imagecolorallocate ($ img, 255,255,255 );

Imageline ($ img, 0, 40,200, 40, $ line_color );
Imageline ($ img, 0,260,200,260, $ line_color );
Imagestring ($ img, 5, 0, 60, "it's time to learn php! ", $ Line_color );

Imagepng ($ img );
Imagedestroy ($ img );

// 5 display Chinese characters in the image.

$ Width = 200;
$ Height = 300;

$ Img = imagecreatetruecolor ($ width, $ height) or die ("gd image processing not supported ");
$ Line_color = imagecolorallocate ($ img, 255,255,255 );
$ Font_type = "c: // windows // fonts // simli. ttf"; // Obtain the truetype font, in which the letter of intent is used

// "Journey to the West" with three hexadecimal characters
$ Cn_char1 = chr (0xe8). chr (0xa5). chr (0xbf );
$ Cn_char2 = chr (0xe6). chr (0xb8). chr (0xb8 );
$ Cn_char3 = chr (0xe8). chr (0xae). chr (0xb0 );

// 4 hexadecimal characters for "Wu Chengen"
$ Cn_str = chr (0xe5 ). chr (0x90 ). chr (0xb4 ). chr (0xe6 ). chr (0x89 ). chr (0xbf ). chr (0xe6 ). chr (0x81 ). chr (0xa9 );
$ Cn_str. = "". chr (0xe8). chr (0x91). chr (0x97 );

Imageline ($ img, 0, 40,200, 40, $ line_color );
Imageline ($ img, 0,260,200,260, $ line_color );

// Display the word "journey to the West" in a vertical bar
Imagettftext ($ img, 30, 0, 10, 80, $ line_color, $ font_type, $ cn_char1 );
Imagettftext ($ img, 30, 0, 10,120, $ line_color, $ font_type, $ cn_char2 );
Imagettftext ($ img, 30, 0, 10,160, $ line_color, $ font_type, $ cn_char3 );

// Display the word "Wu Chengen" in the horizontal layout
Imagettftext ($ img, 15, 0, 90,254, $ line_color, $ font_type, $ cn_str );

Imagepng ($ img );
Imagedestroy ($ img );

// 6 open an existing image.
$ Img = imagecreatefromjpeg ("tower.jpg ");

Imagejpeg ($ img );
Imagedestroy ($ img );

// 7. obtain the attributes of the image.
$ Img = imagecreatefromjpeg ("tower.jpg ");

$ X = imagesx ($ img );
$ Y = imagesy ($ img );
Echo "the width of image tower.jpg is:$ XPixels ";
Echo"
";
Echo"
";
Echo "the height of image tower.jpg is:$ YPixels ";

// Usage of the 8-function getimagesize.
$ Img_info = getimagesize ("tower.jpg ");

For ($ I = 0; $ I <4; ++ $ I)
{
Echo $ img_info [$ I];
Echo"
";
}

?>
1 2 3

....

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.