1 <? Php
2 // proportional scaling of the image
3
4 // because PHP can only operate on resources, you need to copy the image to be scaled and create a new resource.
5. src?imagecreatefrom=('a.jpg ');
6
7 // obtain the width and height of the source Image
8 $size_src1_getimagesize('a.jpg ');
9 $ w = $ size_src ['0'];
10 $ h = $ size_src ['1'];
11
12 // specify the maximum scaled width (or the height)
13 $ max = 300;
14
15 // calculate the length of the other side based on the maximum value of 300 to obtain the scaled image width and height.
16 if ($ w> $ h ){
17 $ w = $ max;
18 $ h = $ h * ($ max/$ size_src ['0']);
19} else {
20 $ h = $ max;
21 $ w = $ w * ($ max/$ size_src ['1']);
22}
23
24
25 // declare a $ w width, $ h high real color image resource
26 $ image = imagecreatetruecolor ($ W, $ H );
27
28
29 // key functions, parameters (Starting coordinates x and y of the target resource, source resource, and target resource, starting coordinates x and y of the source resource, width and height W, H, source resource width/height W, H)
30 imagecopyresampled ($ image, $ SRC, 0, 0, 0, $ W, $ H, $ size_src ['0'], $ size_src ['1']);
31
32 // tell the browser to parse the image
33 header ('content-type: image/PNG ');
34 imagepng ($ image );
35
36 // destroy resources
37 imagedestroy ($ image );
38
39?>
Take a note of the course and use a blog to record it.
I have been in touch with PHP for a short time. I have made many suggestions during the writing process. However, I am not very easy to learn. It is inevitable that there are mistakes. If there are mistakes, I would like to ask you to correct them. I am very grateful!