ActiveStorage wont crop variants

For Rails 6.0 users:

object.image.variant(resize_to_fill: [180, 135, { gravity: 'North' }])

I'm writing this for those who like me didn't know how to use options in variants.


resize_to_fit is an ImageProcessing transformation. Rails 5.2 doesn’t use ImageProcessing; it uses MiniMagick directly instead. Rails 6 will use ImageProcessing.

To resize to fit in Rails 5.2, append > to the resize argument:

@user.image.variant(resize: '180x135>')

To crop, use combine_options so MiniMagick passes the gravity and crop arguments together in a single ImageMagick invocation:

@user.image.variant(combine_options: { gravity: 'Center', crop: '180x135+0+0' })