Specifies a region for the PHP screenshot.

Source: Internet
Author: User
PHP has a lot of code to zoom in and zoom out images, but there seems to be no examples for reference. In fact, it is quite simple. It is similar to narrowing down an image, but the parameters are a little different. For example, the picture in this article (please go to this article to see it yourself ), if I only want to intercept the yellow block of the three caves

There are a lot of PHP code for downgrading/enlarging images, but there seems to be no examples for reference. In fact, it is quite simple, similar to downgrading images, but the parameters are just a little different. For example, the picture in this article (please go to this article to see it yourself ), if I only want to intercept the yellow block of "Three WTI ",

There are a lot of PHP code for downgrading/enlarging images, but there seems to be no examples for reference. In fact, it is quite simple, similar to downgrading images, but the parameters are just a little different. For example, the picture in this article (please go to this article to see it yourself ), if I only want to extract the yellow block of the "Three caves of the rabbit", the following example shows the figure of the block as long as the figure is taken down and executed directly. The annotations in the file have been written (the Source code is placed at the bottom of this article). Just explain the main parameters: imagecopyresampled ($ newim, $ im, 0, 0, 7,174,120, 42, $ new_img_width, $ new_img_height); // original size 120x42 imagecopyresampled ($ newim, $ im, 0, 0,100, 30,500,500, $ new_img_width, $ new_img_height ); // place the screenshot to 500x500 imagecopyresampled ($ newim, $ im, 0, 0,100, 30, 10, 10, $ new_img_width, $ new_img_height ); // After the image is captured, it is reduced to 10x10, which is mainly the operation of this function. It is only possible to check the parameter of the first original size. The following is the parameter of imagecopyresampled, the comparison is as follows: $ newim: imagecreate ($ new_img_width, $ new_img_height); created blank layer $ im: imagecreatefromjpeg ($ filename); read the original image 0: the x point starting from which the output graph starts (the output vertex of the image can be specified. If it is not specified, it will be the layer color or graph you create) 0: the y point starting from which the output graph starts (same as above) 7: The x starting from which the original graph starts (specifying the x point to start) 174: start from which side of the original graph is y (specify the point from which to intercept the block size, which is determined by the following two parameters) 120: how large the width is to be truncated, from the specified position above, start to intercept 120px width (this is also determined if you want to zoom in and out) 42: How much height to intercept, from the specified position above, start to take the 42px height (this is also determined if you want to zoom in and out) $ new_img_width: this is a new graph, from the second set of parameters written above 0, 0, to start drawing multiple widths (currently the specified size in this program) $ new_img_height: this is a new graph, from the second set of parameters 0, 0, the complete code is as follows: Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be encoded inall copies or substantial portions of the Software. the software is provided "as is", without warranty of any kind, express orimplied, including but not limited to the warranties of merchantability, fitness for a particle purpose and noninfringement. in no event shall theauthors or copyright holders be liable for any claim, damages or otherliability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings inthe software. ** PHP program ** @ author: tsung http://plog.longwin.com.tw * @ Desc: http://plog.longwin.com.tw /Programming/2007/11/09/php_snap_image_block_2007 **/header ("Content-type: image/jpeg"); $ filename = 'book_rabbit_rule.jpg '; /* read the image file */$ im = imagecreatefromjpeg ($ filename);/* the length and width of the image */$ new_img_width = 120; $ new_img_height = 42; /* Create a new blank image first */$ newim = imagecreate ($ new_img_width, $ new_img_height); // start x, y, where does the original graph start with x, y, x, y (resize), x, yimagecopyresampled ($ newim, $ im, 0, 0, 7,174,120, 42, $ new_img_width, $ new_img_height);/* display a 500x500 graph * // imagecopyresampled ($ newim, $ im, 0, 0,100, 30,500,500, $ new_img_width, $ new_img_height);/* print the graph */imagejpeg ($ newim);/* Recycle resources */imagedestroy ($ newim ); imagedestroy ($ im);?>

Original article address: PHP captures an image in a specified region. Thank you for sharing it with the original author.

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.