Class: Shipping::PreProcessGenericLabel

Inherits:
BaseService show all
Defined in:
app/services/shipping/pre_process_generic_label.rb

Constant Summary collapse

ROTATION_MAP =

Rotation mapping from degrees to Vips rotation constants

{
  '90' => :d90,
  '-90' => :d270,
  '180' => :d180,
  '-180' => :d180,
  '270' => :d270,
  '-270' => :d90
}.freeze

Instance Method Summary collapse

Methods inherited from BaseService

#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#process(gif_file_path, out_file_name: nil, out_format: 'png', rotate: nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/shipping/pre_process_generic_label.rb', line 14

def process(gif_file_path, out_file_name: nil, out_format: 'png', rotate: nil)
  require 'vips'

  directory_path = File.dirname(gif_file_path)
  base_name = File.basename(gif_file_path, '.*')
  out_file_name ||= "#{directory_path}/#{base_name}.#{out_format}"

  # Load the image
  image = Vips::Image.new_from_file(gif_file_path)

  # Apply rotation if specified
  if rotate.present?
    rotation = ROTATION_MAP[rotate.to_s]
    image = image.rot(rotation) if rotation
  end

  # Write to output format (Vips infers format from extension)
  image.write_to_file(out_file_name)

  out_file_name
end