Module: RnStack::ImageHelper

Defined in:
app/helpers/rn_stack/image_helper.rb

Instance Method Summary collapse

Instance Method Details

#pro_image_tag(attachment, options = {}) ⇒ Object

A professional wrapper for active_storage



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/helpers/rn_stack/image_helper.rb', line 4

def pro_image_tag(attachment, options = {})
  return unless attachment.attached?

  # Default transformations
  transformations = {
    resize_to_limit: options[:size] || [800, 800],
    format: :webp,
    saver: { quality: 80 }
  }

  # Advanced transformations
  transformations[:crop] = "#{options[:crop_w]}x#{options[:crop_h]}+#{options[:x]}+#{options[:y]}" if options[:crop]
  transformations[:monochrome] = true if options[:grayscale]

  image_tag attachment.variant(transformations)
end