Read more

Carrierwave: Built-in resize methods

Emanuel
January 24, 2019Software engineer at makandra GmbH

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 Show archive.org snapshot . You can also use all command line options from RMagick Show archive.org snapshot directly if these helpers are not good enough for you.

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

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

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 Show archive.org snapshot :

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.

Posted by Emanuel to makandra dev (2019-01-24 11:02)