Skip to content
Squeegy edited this page Sep 12, 2010 · 2 revisions

resize(size, options = {})

Performs the common task of resizing this image, constraining proportions. Options allow cropping, stretching, upsampling and padding.

  • size
    is size of the output image after the resize operation. Accepts either 123, '123x456' or [123, 456] format. This format is used throughout the plugin anywhere that an X and Y dimension need to be defined.

Use the following keys in the options hash:

  • :crop
    Pass true to this option to make the output image exactly the same dimensions as size. The default behavior will resize the image without cropping any part meaning the image will be no bigger than the size but may be smaller unless the aspect ration matches exactly. When :crop is true the final image is resized to fit as much as possible in the frame, and then crops off of whatever hangs outside the dimensions declared by the size argument.
  • :upsample
    By default the image will never display larger than its original dimensions, no matter how large the size argument is. Pass true to use this option to allow upsampling, allowing the render of gargantuan images even from small sources. Don’t enable this wihtout a good reason as it may greatly increase processing time and memory usage if very large images get rendered.
  • :padding
    This option will pad the space around your image with a solid color to make it exactly the requested size. Pass true, for the default of white, or give it a text or pixel color like "red" or color(255, 127, 0). This is like the opposite of the crop option. Instead of trimming the image to make it exactly the requested size, it will make sure the entire image is visible, but adds space around the edges to make it the right dimensions.
  • :stretch
    Set this option to true and the image will not preserve its aspect ratio. The final image will stretch to fit the requested size. The resulting image is exactly the size you ask for, albeit stretched or squished to make it fit.

Example

@photo.operate do |image|
  image.resize '200x200', :crop => true
end

Back to Operators

Clone this wiki locally