igorkasyanchuk / active_storage_validations

Do it like => validates :photos, attached: true, content_type: ['image/png', 'image/jpg', 'image/jpeg'], size: { less_than: 500.kilobytes }, limit: { min: 1, max: 3 }, aspect_ratio: :landscape, dimension: { width: { in: 800..1600 }
https://www.railsjazz.com/
MIT License
1.02k stars 130 forks source link

Refactor the `metadata.rb` using built-in `ActiveStorage::Analyzer::ImageAnalyzer::ImageMagick/Vips.new(blob).metadata` #254

Open Mth0158 opened 3 months ago

Mth0158 commented 3 months ago

Reading Rails documentation to implement a feature for this gem, I came across the following ActiveStorage class: https://github.com/rails/rails/blob/55c4adeb36eff229972eecbb53723c1b80393091/activestorage/lib/active_storage/analyzer/image_analyzer.rb

It looks like it both supports MiniMagick and Vips since June 2021. The metadata.rb file however was built a few years before maybe explaining its presence?

We could rely on ActiveStorage::Analyzer::ImageAnalyzers to do this job, therefore decreasing the weight + associated unnecessary complexity of this gem?

UPDATE : We can't rely on ActiveStorage::Analyzer::ImageAnalyzers to do this job because it needs a saved blob, ie with its io uploaded. We only have not uploaded attachables at this point, but we can copy their structure to refactor metadata.rb (which could be a very nice addition)

@igorkasyanchuk @gr8bit what do you think of it?