Rails Paperclip插件 - 调整大小的样式选项

时间:2022-10-31 08:56:23

So, I want to resize images to a FIXED width, but proportional height.

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

I have been trying a wide range of operators:

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

380x242# 380x242> 380!x242 380x242<

380x242#380x242> 380!x242 380x242 <

none of them have the desired effect. Any help? I want it to fill or resize to the 380 width, then resize / shrink the height by the same factor it used to shrink or resize the image to 380 wide.

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

5 个解决方案

#1


56  

Try using 380x

尝试使用380x

This should resize width to 380px and keep original aspect ratio.

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

For all available options for resizing images go here: http://www.imagemagick.org/script/command-line-processing.php?ImageMagick=lj6pre8q2iautc3ch6nuph1fc2#geometry

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

#2


39  

"#" is an argument used by Paperclip to know whether or not you expect the pic to be cropped. Using "100x100#" will scale and crop the picture exactly to that size. %@!<> are arguments in the Geometry String used by ImageMagick. One can use the following ImageMagick geometry strings for resizing images:

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

  • Ignore Aspect Ratio ('!')
  • 忽略纵横比('!')
  • Only Shrink Larger ('>')
  • 只收缩('>')
  • Only Enlarge Smaller ('<')
  • 只放大小('<')
  • Fill Given Area ('^')
  • 填充给定区域('^')
  • Percentage Resize ('%')
  • 调整百分比('%')
  • Pixel Count Limit ('@')
  • 像素数限制('@')

According to the ImageMagick documentation for Image Geometry the geometry argument can be

根据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.

#3


7  

you can use , :show => '786>x447' for fixed width and prorortional height

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

#4


1  

The resizing options are limited but you can also use paperclip custom processors to resize images dynamically.

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

Railscasts has a good example of using a custom processor for paperclip, though his example allows a user to crop an image. http://railscasts.com/episodes/182-cropping-images

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

#5


0  

You can calculate the height yourself:

你可以自己计算高度:

newHeight = oldHeight * 380 / oldWidth

newHeight = oldHeight * 380 / oldWidth

#1


56  

Try using 380x

尝试使用380x

This should resize width to 380px and keep original aspect ratio.

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

For all available options for resizing images go here: http://www.imagemagick.org/script/command-line-processing.php?ImageMagick=lj6pre8q2iautc3ch6nuph1fc2#geometry

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

#2


39  

"#" is an argument used by Paperclip to know whether or not you expect the pic to be cropped. Using "100x100#" will scale and crop the picture exactly to that size. %@!<> are arguments in the Geometry String used by ImageMagick. One can use the following ImageMagick geometry strings for resizing images:

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

  • Ignore Aspect Ratio ('!')
  • 忽略纵横比('!')
  • Only Shrink Larger ('>')
  • 只收缩('>')
  • Only Enlarge Smaller ('<')
  • 只放大小('<')
  • Fill Given Area ('^')
  • 填充给定区域('^')
  • Percentage Resize ('%')
  • 调整百分比('%')
  • Pixel Count Limit ('@')
  • 像素数限制('@')

According to the ImageMagick documentation for Image Geometry the geometry argument can be

根据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.

#3


7  

you can use , :show => '786>x447' for fixed width and prorortional height

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

#4


1  

The resizing options are limited but you can also use paperclip custom processors to resize images dynamically.

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

Railscasts has a good example of using a custom processor for paperclip, though his example allows a user to crop an image. http://railscasts.com/episodes/182-cropping-images

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

#5


0  

You can calculate the height yourself:

你可以自己计算高度:

newHeight = oldHeight * 380 / oldWidth

newHeight = oldHeight * 380 / oldWidth