ImageCopyResampled struggled for a long time and asked for expert assistance. Test Code: required); & nbsp; // The image size is 200*150 & nbsp; $ newimg & nbs ImageCopyResampled.
Test code:
$ CreateImg = imagecreatefrom(('x.jpg '); // The image size is 200*150.
$ Newimg = imagecreatetruecolor (200,150 );
ImageCopyResampled ($ newimg, $ createImg, 200, $ start_w = 0, $ start_h = 0, $ width = 150, $ height = 200, $ end_w =, $ end_h = 150 );
Imagejpeg ($ newimg );
Several parameter values have been viewed in the manual and probably understood their functions. However, some parameters have been tested and are not expected.
SOURCE image:
For example:
1. set $ end_w = 200, $ end_h = 150, that is, the width and height of the source file. I set it to $ end_w = 400, $ end_h = 300; in my understanding, the image is enlarged and then scaled to 300*150, which is the same as setting to $ end_w = 200, $ end_h = 150.
:
Unexpectedly, the height and width change to 100*75. I think this function is used to calculate the ratio of the height and width of the source image to the width and height of the new image. Then, the ratio is exceeded by the actual width and height of the source image.
I set $ end_w = 200 and $ end_h = 150 to a value smaller than the source image. For example, set $ end_w = 100, $ end_h = 150
The function truncates the source image width by 100 and then pulls it until 200.
:
2. set $ start_w = 0, $ start_h = 12.5. you want to compress the image to 100*75 and take the middle part of the 50 section. Set
$newimg = imagecreatetruecolor(100,50);
ImageCopyResampled($newimg,$createImg,0,0, $start_w=0, $start_h=24.5, $width=100,$height=75, $end_w=200,$end_h=150)
Generating an image is a 24.5 pressure on the source image, and the excess 24.5 below is limited by the size of the canvas and invisible. This achieves the expected goal. I wonder whether this implementation method is correct.
:
After pressing 100*75, it is calculated through 75/2 that the 12.5 cut on both sides should be the same. I wonder if it can be implemented.
Shortly after getting started with this function, you may give more comments. the more you say, the better. Thank you!
------ Solution --------------------
First, you need to enlarge the source image to remove this argument.
This statement will only mislead you
The source image is only 200*150
So (201, 1) must be outside the graph
The figure does not become larger, but you only set the value outside the graph.