Class: JekyllImgFlow::Tags::CropTag

Inherits:
BaseTag
  • Object
show all
Defined in:
lib/jekyll-imgflow/tags/crop_tag.rb

Overview

Crop tag - processes image cropping (validation handled by Parser)

Instance Method Summary collapse

Methods inherited from BaseTag

#initialize

Constructor Details

This class inherits a constructor from JekyllImgFlow::Tags::BaseTag

Instance Method Details

#process(input_path, output_path, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jekyll-imgflow/tags/crop_tag.rb', line 9

def process(input_path, output_path, options = {})
  ensure_output_dir(output_path)

  # Validate that crop information is provided
  ratio = options[:ratio] || options[:aspect_ratio]
  has_pixel_crop = options[:width] || options[:height]

  unless ratio || has_pixel_crop
    raise ArgumentError,
          "Crop operation requires ratio or at least one dimension (width or height)"
  end

  if ratio
    # Handle aspect ratio cropping (e.g., "16:9", "4:3")
    validate_ratio(ratio)
    handle_aspect_ratio_crop(input_path, output_path, ratio, options)
  else
    # Handle pixel-based cropping with flexible dimensions
    validate_positive_integer(options[:width], "width") if options[:width]
    validate_positive_integer(options[:height], "height") if options[:height]
    validate_positive_integer(options[:x], "x") if options[:x]
    validate_positive_integer(options[:y], "y") if options[:y]
    handle_pixel_crop(input_path, output_path, options)
  end

  @provider.execute(input_path, output_path)
end