How to intercept a specified image size in PHP, _PHP tutorial

WBOY
Release: 2016-07-13 10:12:05
Original
1021 people have browsed it

How to intercept a specified image size in PHP,

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:

Copy code The code is as follows:
header("Content-type: image/jpeg");

$filename = 'book_rabbit_rule.jpg';
/* Read image files */
$im = imagecreatefromjpeg($filename);
/* How much of the picture should be cut, length/width */
$new_img_width = 120;
$new_img_height = 42;
/* First create a new blank image file */
$newim = imagecreate($new_img_width, $new_img_height);
// From which side should the output image start x, y , where should the original image start x, y , how big should we draw x, y (resize), how big should we grab x, y
imagecopyresampled($newim, $im, 0, 0, 7, 174, 120, 42, $new_img_width, $new_img_height);
/* Zoom in to 500 x 500 image */
// imagecopyresampled($newim, $im, 0, 0, 100, 30, 500, 500, $new_img_width, $new_img_height);
/* Print the image */
imagejpeg($newim);
/* Resource recovery */
imagedestroy($newim);
imagedestroy($im);

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/925127.htmlTechArticleHow to intercept the specified image size in PHP. 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...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!