2010-06-16 30 views
24

所以,我想调整图像大小到固定宽度,但是比例高度。Rails回形针插件 - 用于调整大小的样式选项

我一直在尝试多种运营商:

380x242# 380x242> 380 X242 380x242 <

他们没有收到预期的效果。任何帮助?我想要它填充或调整到380宽度,然后调整/缩小高度的相同因素,它用于缩小或调整图像的宽度为380。

回答

55

尝试使用380X

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

用于调整图像大小的可用选项,去这里:http://www.imagemagick.org/script/command-line-processing.php?ImageMagick=lj6pre8q2iautc3ch6nuph1fc2#geometry

+2

如果可以的话,我会给你两个upvotes。完全保存我的一天,而不必玩:covert_options。干杯 – 2012-09-27 03:07:39

+1

根据你的链接,它不应该只是380? – Puce 2014-10-21 08:55:28

+0

看来您现在可以只使用没有x号的宽度。我想他们在我写回答后的4年中改变了它。另外我假设380x(带x)仍然可以用于向后兼容。 – 2014-10-21 11:57:59

0

您可以自己计算高度:

newHeight = oldHeight * 380/oldWidth

+0

我不认为这是可能的回形针插件的样式选项。 – 2010-06-16 06:12:59

+0

我的回答后编辑了这个问题。 – Sjoerd 2010-06-16 06:45:14

7

你可以使用,:秀=> '786> X447'固定宽度和prorortional高度

39

“#” 是一个参数由Paperclip使用来了解你是否期望照片被裁剪。使用“100x100#”将缩放和裁剪照片的大小。 %@! <>是ImageMagick使用的Geometry String中的参数。我们可以使用下面的ImageMagick的几何字符串resizing images

  • 忽略长宽比
  • 只能收缩较大( '>')
  • 只放大较小( '<')
  • ( '!')填写特定地区( '^')
  • 比例调整尺寸( '%')
  • 像素数限制( '@')

根据ImageMagick的文档Image 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.