Active Storage: How to create "named variants" that are cropped by user-supplied coordinates

The idea of named variants (merged pull request) is to be able to define image variants (i.e. different sizes) in 1 place (in the Model), instead of redundantly and all over your Views.

But, if you’re in a situation in which you need to…

  1. Keep the uploaded original image unchanged, and
  2. Crop the image (based on coordinates supplied by the user), to then:
  3. Create several variants (based on the cropped version)

… I believe that this would be impossible in the current version of “named variants”, an example of which looks like this:

class User < ApplicationRecord

  has_one_attached :avatar do |attachable|
    attachable.variant :large,  resize_to_limit: [300, nil]
    attachable.variant :medium, resize_to_limit: [100, nil]
    attachable.variant :small,  resize_to_limit: [ 50, nil]
  end

end

Or am I missing something?

Would this be an idea for an update to the Rails core?

How I’ve done this type of thing with dragonfly (similar to active storage) is you store the user’s crop coordinates/dimentions as a json object or string. Then use that in the views image helper based on current_user or whatever. Your example can only handle predefined options from the looks of it