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 online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)