25

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

I have been trying a wide range of operators:

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.

Jonathan Soeder
  • 847
  • 1
  • 7
  • 13

5 Answers5

56

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

Slobodan Kovacevic
  • 6,848
  • 3
  • 29
  • 33
  • 2
    I would give you two upvotes if I could. Save my day totally instead of having to play with :covert_options. Cheers – Damon Aw Sep 27 '12 at 03:07
  • 1
    According your link, shouldn't it be just 380 ? – Puce Oct 21 '14 at 08:55
  • It seems that you can now use only width without x sign. I guess they changed it in past 4 years since my answer was written. Also I assume that 380x (with x) will still work for backward compatibility. – Slobodan Kovacevic Oct 21 '14 at 11:57
41

"#" 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.
0x4a6f4672
  • 27,297
  • 17
  • 103
  • 140
7

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

arvind
  • 71
  • 1
  • 1
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

LessQuesar
  • 3,123
  • 1
  • 21
  • 29
0

You can calculate the height yourself:

newHeight = oldHeight * 380 / oldWidth

Sjoerd
  • 74,049
  • 16
  • 131
  • 175