开发者

Why does cropping behave like that?

开发者 https://www.devze.com 2023-02-25 09:40 出处:网络
I\'ve got an image with dimensions 126x75: (rdb:1) p image.width 126 (rdb:1) p image.height 57 Now I want to crop it down to 50x50, beginning at the north west (top left corner). So I tried that (w

I've got an image with dimensions 126x75:

(rdb:1) p image.width
126
(rdb:1) p image.height
57

Now I want to crop it down to 50x50, beginning at the north west (top left corner). So I tried that (which should be similar to IMs command line geometry parameter 50x50+0+0):

image2 = image.process(:crop, :width => 50, :height => 50, :x => 0, :y => 0)

But the result is somewhat surprising to me:

开发者_如何学编程(rdb:1) p image2.width
24
(rdb:1) p image2.height
16

Why does it happen like that? What's the right way?


It sounds like the image you're using has existing page geometry that is causing your (0,0) location to be offset. You can tell IM to repage the image to remove the existing page geometry so that (0,0) is the "true" (0,0). Check the IM documenation: http://www.imagemagick.org/Usage/crop/#crop_page

0

精彩评论

暂无评论...
验证码 换一张
取 消