Jonathan Soeder
Jonathan Soeder

Reputation: 847

Rails Paperclip Plugin - Style Options for Resizing

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.

Upvotes: 25

Views: 13619

Answers (5)

0x4a6f4672
0x4a6f4672

Reputation: 28245

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

Upvotes: 41

LessQuesar
LessQuesar

Reputation: 3193

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

Upvotes: 1

arvind
arvind

Reputation: 71

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

Upvotes: 7

Slobodan Kovacevic
Slobodan Kovacevic

Reputation: 6888

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

Upvotes: 56

Sjoerd
Sjoerd

Reputation: 75599

You can calculate the height yourself:

newHeight = oldHeight * 380 / oldWidth

Upvotes: 0

Related Questions