Posted 11 months ago. Visible to the public.

Carrierwave: Built-in resize methods

Carrierwave includes some handy helper methods you can use to resize your images. Here is a quick summary of them, if you need more details read the docs. You can also use all command line options from RMagick directly if these helpers are not good enough for you.

Copy
resize_to_limit(width, height) resize_to_fit(width, height) resize_to_fill(width, height, gravity = 'Center') resize_and_pad(width, height, background = :transparent, gravity = 'Center')

resize_to_limit

Resize the image to fit within the specified dimensions while retaining
the original aspect ratio. Will only resize the image if it is larger than the
specified dimensions. The resulting image may be shorter or narrower than specified
in the smaller dimension but will not be larger than the specified values.

resize_to_fit

Resize the image to fit within the specified dimensions while retaining
the original aspect ratio. The image may be shorter or narrower than
specified in the smaller dimension but will not be larger than the specified values.

resize_to_fill

Resize the image to fit within the specified dimensions while retaining
the aspect ratio of the original image. If necessary, crop the image in the
larger dimension.

resize_and_pad

Resize the image to fit within the specified dimensions while retaining
the original aspect ratio. If necessary, will pad the remaining area
with the given color, which defaults to transparent (for gif and png,
white for jpeg).


Side note about MiniMagick and RMagick from the Carrierwave README:

MiniMagick is similar to RMagick but performs all the operations using the 'mogrify' command which is part of the standard ImageMagick kit. This allows you to have the power of ImageMagick without having to worry about installing all the RMagick libraries. Currently, the MiniMagick carrierwave processor provides exactly the same methods as for the RMagick processor.

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Owner of this card:

Avatar
Emanuel De
Last edit:
11 months ago
by Emanuel De
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Emanuel De to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more