1
4

1 回答 1

0

Yes, arbitrary affine transformations can be done through the URL API, but you have to know the order of events and you'll have to split the cropping and padding into separate commands.

Cropping happens before resizing, so you'll need to figure out your viewport dimension and split them into two sets of coordinates.

1) Crop values are x1,y1,x2,y2, in source image coordinates. You can use cropxunits=100 and cropyunits=100 to make x1,y1,x2,y2 percentages of width/height respectively if you don't know the viewport coordinates in image dimensions. You can also use arbitrary values for cropxunits and cropyunits to make the math easier.

Negative crop values will be relative to bottom-right instead of top left, so after copying the absolute value of negative (or, for far right values, the excess amounts) into variables for padding later, set them to zero or width/height/cropxunits/cropyunits.

2) Add padding if needed with margin=left, top, right, bottom. Units are display pixels, not source pixels, so these values should be unscaled.

3) Scale - This is where you apply width=x&height=y&mode=max to get the appropriate display size. Left off, it will show 1:1 zoom, which may or may not be desired. x and y here should be the desired width/height of the image in display pixels, NOT the canvas.

See full command reference for details.

You can definitely do this as a plugin, but I'd suggest doing a javascript implementation first, then seeing if you want to bother putting the wrapping on the server in plugin form. Either way, I've had this question a few times and an MIT-licensed code sample would be very helpful to the community.

于 2012-07-05T14:47:53.503 回答