Module: Locomotive::Steam::Liquid::Filters::Resize

Defined in:
lib/locomotive/steam/liquid/filters/resize.rb

Instance Method Summary collapse

Instance Method Details

#resize(input, resize_string, *args) ⇒ Object

Optional args include:

quality: <number> compress image
auto_orient: <true|false> fix EXIF orientation issues
strip: <true|false> remove extra possibly unnecessary metadata
progressive: <true|false> make JPEG progressive
optimize: <number> shortcut to quality: and also applies strip and progressive
filters: <string> access to any ImageMagick arguments


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/locomotive/steam/liquid/filters/resize.rb', line 14

def resize(input, resize_string, *args)
  args ||= {}
  options = []

  args.flatten.each do |arg|
    arg.each do |k, v|
      options << case k.to_sym
      when :quality
        "-quality #{v}"
      when :optimize # Shortcut helper to set quality, progressive and strip
        "-quality #{v} -strip -interlace Plane"
      when :auto_orient
        "-auto-orient" if v
      when :strip
        "-strip" if v
      when :progressive
        "-interlace Plane" if v
      when :filters
        v
      else
        next
      end
    end
  end

  @context.registers[:services].image_resizer.resize(input, resize_string, options.join(' '))
end