Recently in the study of PHP, because the project needs to use the thumbnail, if the thumbnail is not cropped, you will find that the image becomes grotesque, not conducive to typesetting. So here's a quick introduction to the idea of creating a center thumbnail:
A picture 480*800
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6F/0B/wKioL1WQwCaQGkPPAAKRfEgF3mc371.jpg "title=" 1.png " alt= "Wkiol1wqwcaqgkppaakrfegf3mc371.jpg"/>
Now I'm going to cut it into a 240*240 picture.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6F/0B/wKioL1WQwGShBReHAACWxp1cPRw993.jpg "title=" x1.png "alt=" Wkiol1wqwgshbrehaacwxp1cprw993.jpg "/>
Similar to the one above.
1. First we need to calculate whether the zoom is the width first or high priority, if it is like above is the width first.
The scale is
Ratio = IMAGE_WIDTH_DST/IMAGE_WIDTH_SRC
2. Depending on the scale, the height of the reduction is
Image_height_pre = image_height_src * ratio
3. Get the height after zooming, minus the height that needs to be generated, that is, the remaining height after shrinking
Image_height_rem = IMAGE_HIEGHT_PRE-IMAGE_HEIGHT_DST
4. Finally calculate where to start cropping
Start_cut = Image_height_rem * IMAGE_WIDTH_SRC/IMAGE_WIDTG_DST/2
The above formula is not good to understand:
Summarize:
Formula for width precedence
Start clipping coordinates = (original height * (Target wide chart/Huantuquan)-Target graph height) * (former wide chart/target wide chart)/2
High-priority formula
Start clipping coordinates = (Original width * (target graph height/Huantugau)-Target wide chart) * (original height/target height)/2
Difficulties:
When you get to the remaining height of the crop, you also need to revert to the proportions of the original picture.
Divide by 2, to center, to empty the 2-terminal position.
This article is from "Maple Night" blog, please be sure to keep this source http://fengwan.blog.51cto.com/508652/1668970
An algorithm for creating a center thumbnail image