Rails Paperclip Plugin - Style Options for Resizing

[亡魂溺海] 提交于 2019-11-29 20:59:37

Try using 380x

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

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

"#" 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:

  • 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

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.

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

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

You can calculate the height yourself:

newHeight = oldHeight * 380 / oldWidth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!