Class: TileUp::ImageProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/tileup/image_processor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ ImageProcessor

Returns a new instance of ImageProcessor.



12
13
14
# File 'lib/tileup/image_processor.rb', line 12

def initialize logger
  self.logger = logger
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



3
4
5
# File 'lib/tileup/image_processor.rb', line 3

def logger
  @logger
end

Class Method Details

.build(processor, logger) ⇒ Object



5
6
7
8
9
10
# File 'lib/tileup/image_processor.rb', line 5

def self.build(processor, logger)
  case processor
  when 'mini_magick' then TileUp::ImageProcessors::MiniMagick.new(logger)
  else TileUp::ImageProcessors::RMagick.new(logger)
  end
end

Instance Method Details

#crop_and_save(image, crop, filename:, extend_crop: false, extend_color: 'none') ⇒ Object



35
36
37
38
# File 'lib/tileup/image_processor.rb', line 35

def crop_and_save image, crop, filename:, extend_crop: false, extend_color: 'none'
  logger.verbose "Crop: x: #{crop[:x]}, y: #{crop[:y]}, w: #{crop[:width]}, h: #{crop[:height]}"
  crop_and_save_image(image, crop, filename: filename, extend_crop: extend_crop, extend_color: extend_color)
end

#height(image) ⇒ Object

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/tileup/image_processor.rb', line 46

def height image
  raise NotImplementedError
end

#open(image_filename) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/tileup/image_processor.rb', line 16

def open image_filename
  image = open_image(image_filename)
  logger.info "Opened #{image_filename}, #{width(image)} x #{height(image)}"
  image
rescue => e
  logger.error "Could not open image #{image_filename}: #{e.message}"
  raise e
end

#scale(image, scale) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/tileup/image_processor.rb', line 25

def scale image, scale
  logger.verbose "Scale: #{scale}"

  if scale != 1.0
    scale_image(image, scale)
  else
    image
  end
end

#width(image) ⇒ Object

Interface

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/tileup/image_processor.rb', line 42

def width image
  raise NotImplementedError
end