-
Notifications
You must be signed in to change notification settings - Fork 49
OperatorResize
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 either123,'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
Passtrueto this option to make the output image exactly the same dimensions assize. The default behavior will resize the image without cropping any part meaning the image will be no bigger than thesizebut may be smaller unless the aspect ration matches exactly. When:cropistruethe 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 thesizeargument.
-
:upsample
By default the image will never display larger than its original dimensions, no matter how large thesizeargument is. Passtrueto 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 requestedsize. Passtrue, for the default ofwhite, or give it a text or pixel color like"red"orcolor(255, 127, 0). This is like the opposite of thecropoption. 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 totrueand the image will not preserve its aspect ratio. The final image will stretch to fit the requestedsize. The resulting image is exactly the size you ask for, albeit stretched or squished to make it fit.
@photo.operate do |image|
image.resize '200x200', :crop => true
end