开发者

Paperclip not resizing images to specified dimensions

开发者 https://www.devze.com 2023-01-31 04:55 出处:网络
The images sure are getting resized but not to the specified dimensions even though I have attached large images. For example, a \'791 X 1015\' image was resized like this

The images sure are getting resized but not to the specified dimensions even though I have attached large images. For example, a '791 X 1015' image was resized like this

Specified - Resized

400 X 250 - 195 X 250

89 X 50 开发者_如何学编程 - 39 X 50

Here's my code:

has_attached_file :data, :styles => { :medium => "400x250>", :small => "150x150>", :thumb => "80x50>" }

I'm using

Paperclip 2.3.8

Ruby 1.8.7

Rails 2.3.2

Ubuntu 10.04

Any ideas ? Thanks!


ImageMagick is maintaining the image aspect ratio

widthxheight>   Change as per widthxheight but only if an image dimension exceeds a specified dimension

So for an image of 791 x 1015 pixels, it would be resized to an image of size 195 x 250. If you want it to fit in 400 x 250 ignoring aspect ratio, you must use widthxheight!

More info here:
http://www.imagemagick.org/script/command-line-processing.php#geometry


the behaviour you are getting is correct. see http://www.imagemagick.org/script/command-line-processing.php?ImageMagick=lj6pre8q2iautc3ch6nuph1fc2#geometry for the different options on the style dimensions and what they do.

for example, 400x250> means resize if atleast one dimension exceeds the max and then resize preserving aspect ratio. so 195x250 is the largest image that fits in the dimensions you gave that preserved the aspect ratio.

if you want to resize to exactly 400x250 and not care about aspect ratio you can use 400x250! instead of 400x250>

0

精彩评论

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

关注公众号