Class: Airbrush::Processors::Image::Rmagick

Inherits:
ImageProcessor show all
Defined in:
lib/airbrush/processors/image/rmagick.rb

Constant Summary collapse

VALID_OUTPUT_FORMATS =
['JPEG', 'PNG', 'JPG', 'GIF']

Instance Method Summary collapse

Methods inherited from ImageProcessor

after_filter, before_filter, #dispatch, #filter_dispatch

Methods inherited from Processor

#dispatch, filter_params

Instance Method Details

#crop(image, tl_x, tl_y, br_x, br_y) ⇒ Object



20
21
22
23
24
# File 'lib/airbrush/processors/image/rmagick.rb', line 20

def crop(image, tl_x, tl_y, br_x, br_y)
  process image do
    crop!(tl_x, tl_y, br_x, br_y)
  end
end

#crop_resize(image, width, height = nil) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/airbrush/processors/image/rmagick.rb', line 26

def crop_resize(image, width, height = nil)
  width, height = calculate_dimensions(image, width) unless height
  
  process image do
    crop_resized!(width, height)
  end
end

#exif_data(image) ⇒ Object



40
41
42
43
# File 'lib/airbrush/processors/image/rmagick.rb', line 40

def exif_data(image)
  data = Magick::Image.from_blob(image).first.get_exif_by_entry
  data.inject({}) { |m, exif_entry| m[exif_entry[0]] = exif_entry[1]; m }
end

#previews(image, sizes) ⇒ Object

sizes => { :small => [200,100], :medium => [400,200], :large => [600,300] }



34
35
36
37
38
# File 'lib/airbrush/processors/image/rmagick.rb', line 34

def previews(image, sizes) # sizes => { :small => [200,100], :medium => [400,200], :large => [600,300] }
  images = sizes.inject(Hash.new) { |m, (k, v)| m[k] = crop_resize(image, *v); m }
  images[:original] = dimensions(image)
  images
end

#resize(image, width, height = nil) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/airbrush/processors/image/rmagick.rb', line 12

def resize(image, width, height = nil)
  width, height = calculate_dimensions(image, width) unless height

  process image do
    change_geometry("#{width}x#{height}") { |cols, rows, image| image.resize!(cols, rows) }
  end
end

#resized_crop_mask(image, crop, size) ⇒ Object



45
46
47
48
49
50
# File 'lib/airbrush/processors/image/rmagick.rb', line 45

def resized_crop_mask(image, crop, size)
  process image do
    resize!(size[:width], size[:height])
    crop!(crop[:x], crop[:y], crop[:width], crop[:height], true) # pass true to clear offset info
  end
end