Home >Backend Development >PHP Tutorial >How to intercept a specified image size in PHP, _PHP tutorial
The example in this article describes the method of intercepting the specified image size in PHP. Share it with everyone for your reference. The specific analysis is as follows:
imagecopyresampled($newim, $im, 0, 0, 7, 174, 120, 42, $new_img_width, $new_img_height); // Original size 120 x 42
imagecopyresampled($newim, $im, 0, 0, 100, 30, 500, 500, $new_img_width, $new_img_height); //Cut out the image and place it at 500 x 500
imagecopyresampled($newim, $im, 0, 0, 100, 30, 10, 10, $new_img_width, $new_img_height); // After the image is cut out, reduce it to 10 x 10
It’s probably just the operation of this function. Just look at the first parameter of the original size and compare it. The following are the parameters of imagecopyresampled. Compare them one by one as follows:
$newim: imagecreate($new_img_width, $new_img_height); Created blank layer
$im: imagecreatefromjpeg($filename); Read in the original image
0: The x point from which side the output image should start (the point of image output can be specified, and the unspecified position will be the layer color or image you created)
0: The y point from which side the output graph should start (same as above)
7: From which side x of the original image should you start (specify which x point should you start cutting from)
174: From which side of the original image y (specify the point from which to intercept, the size of the intercepted block is determined by the following two parameters)
120: How big is the width of the screenshot, starting from the specified position above, 120px wide (if you want to zoom in or out, it is also determined here)
42: How big should be the height of the screenshot? Starting from the specified position above, the height will be 42px (if you want to zoom in or out, it is also determined here)
$new_img_width: This is a new picture. From the second set of parameters 0, 0 written above, how wide to start drawing (in this program, the size of the screenshot is currently specified)
$new_img_height: This is a new picture. From the second set of parameters 0, 0 above, how high should you start drawing (in this program, the size of the screenshot is currently specified)
PHP example code is as follows:
I hope this article will be helpful to everyone’s PHP programming design.