Class: Bridgetown::ImagePipeline::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/bridgetown/image_pipeline/processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(config:, output_root:) ⇒ Processor

Returns a new instance of Processor.



9
10
11
12
# File 'lib/bridgetown/image_pipeline/processor.rb', line 9

def initialize(config:, output_root:)
  @config = config
  @output_root = output_root
end

Instance Method Details

#process(source_path, basename:) ⇒ Object



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
# File 'lib/bridgetown/image_pipeline/processor.rb', line 14

def process(source_path, basename:)
  image = Vips::Image.new_from_file(source_path)
  source_width  = image.width
  source_height = image.height
  original_ext  = File.extname(source_path).downcase.delete(".")
  original_ext  = "jpg" if original_ext == "jpeg"

  variants = []

  @config.widths.each do |target_width|
    next if target_width > source_width

    @config.formats.each do |fmt|
      variants << build_variant(source_path, basename, target_width, fmt)
    end

    variants << build_variant(source_path, basename, target_width, original_ext.to_sym)
  end

  {
    width: source_width,
    height: source_height,
    variants: variants
  }
end