【发布时间】:2011-03-04 07:45:17
【问题描述】:
所以,我想将图像调整为固定宽度,但高度成比例。
我一直在尝试各种运算符:
380x242# 380x242> 380!x242 380x242
它们都没有达到预期的效果。有什么帮助吗?我希望它填充或调整到 380 宽度,然后将高度调整 / 收缩其用于将图像缩小或调整到 380 宽度的相同因子。
【问题讨论】:
标签: ruby-on-rails imagemagick paperclip
所以,我想将图像调整为固定宽度,但高度成比例。
我一直在尝试各种运算符:
380x242# 380x242> 380!x242 380x242
它们都没有达到预期的效果。有什么帮助吗?我希望它填充或调整到 380 宽度,然后将高度调整 / 收缩其用于将图像缩小或调整到 380 宽度的相同因子。
【问题讨论】:
标签: ruby-on-rails imagemagick paperclip
尝试使用 380 倍
这应该将宽度调整为 380 像素并保持原始纵横比。
有关调整图像大小的所有可用选项,请访问此处:http://www.imagemagick.org/script/command-line-processing.php?ImageMagick=lj6pre8q2iautc3ch6nuph1fc2#geometry
【讨论】:
"#" 是 Paperclip 用来了解您是否希望图片被裁剪的参数。使用“100x100#”将图片缩放和裁剪到该尺寸。 %@! 是 ImageMagick 使用的 Geometry String 中的参数。可以将以下 ImageMagick 几何字符串用于resizing images:
根据Image Geometry 的 ImageMagick 文档,几何参数可以是
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' 固定宽度和比例高度
【讨论】:
调整大小选项有限,但您也可以使用回形针自定义处理器动态调整图像大小。
Railscasts 有一个使用自定义处理器处理回形针的很好的示例,尽管他的示例允许用户裁剪图像。 http://railscasts.com/episodes/182-cropping-images
【讨论】:
你可以自己计算高度:
newHeight = oldHeight * 380 / oldWidth
【讨论】: