Rails Paperclip插件 – resize的样式选项

所以,我想将图像调整为FIXED宽度,但比例高度。

我一直在尝试各种各样的运营商:

380×242#380×242> 380!x242 380×242 <

它们都没有达到预期的效果。 有帮助吗? 我希望它填充或resize为380宽度,然后调整高度/缩小高度,使其缩小或缩小图像大小为380宽度。

尝试使用380x

这应该将宽度调整为380px并保持原始宽高比。

有关调整图像大小的所有可用选项,请访问: http : //www.imagemagick.org/script/command-line-processing.php? ImageMagick = lj6pre8q2iautc3ch6nuph1fc2 #geometry

“#”是Paperclip使用的参数,用于了解您是否期望裁剪图片。 使用“100×100#”将缩放并将图片精确裁剪为该尺寸。 %@!<>是ImageMagick使用的Geometry String中的参数。 可以使用以下ImageMagick几何字符串来调整图像大小 :

  • 忽略纵横比(’!’)
  • 只收缩(’>’)
  • 只放大小(’<')
  • 填充给定区域(’^’)
  • 调整百分比(’%’)
  • 像素数限制(’@’)

根据Image Geometry的ImageMagick文档,geometry参数可以是

scale% Height and width both scaled by specified percentage scale-x%xscale-y% Height and width individually scaled by specified percent width Height automagically selected to preserve aspect ratio xheight Width automagically selected to preserve aspect ratio widthxheight Maximum values of height and width given, ratio preserved widthxheight^ Minimum values of width and height given, ratio preserved widthxheight! Width and height emphatically given, ignore original ratio widthxheight> Change only if an image dimension exceeds a specified dim. widthxheight< Change only if both image dimensions exceed specified dim. 

你可以使用,:show =>’786> x447′来确定固定宽度和高度

resize选项有限,但您也可以使用回形针自定义处理器动态调整图像大小。

Railscasts有一个使用自定义处理器用于回形针的好例子,尽管他的例子允许用户裁剪图像。 http://railscasts.com/episodes/182-cropping-images

你可以自己计算高度:

newHeight = oldHeight * 380 / oldWidth