Class: Imgry::Processor::ImgScalr

Inherits:
JavaAdapter show all
Defined in:
lib/imgry/processor/img_scalr.rb

Instance Attribute Summary

Attributes inherited from Adapter

#format, #img, #img_blob

Instance Method Summary collapse

Methods inherited from JavaAdapter

#clean!, #crop_geometry, #detect_image_format!, #format, from_file, #height, #save, supported_formats, #to_blob, #width, with_bytes

Methods inherited from Adapter

#aspect_ratio, from_file, #initialize, #inspect, load_lib!, with_bytes

Constructor Details

This class inherits a constructor from Imgry::Processor::Adapter

Instance Method Details

#crop!(geometry) ⇒ Object



32
33
34
35
36
# File 'lib/imgry/processor/img_scalr.rb', line 32

def crop!(geometry)
  width, height, offset_x, offset_y, flag = crop_geometry(geometry)

  @img = Scalr.crop(@img, offset_x, offset_y, width, height)
end

#load_image!Object



8
9
10
11
12
13
14
15
16
# File 'lib/imgry/processor/img_scalr.rb', line 8

def load_image!
  begin
    input_stream = ImageIO.create_image_input_stream(ByteArrayInputStream.new(@img_blob))
    detect_image_format!(input_stream)
    @img = ImageIO.read(input_stream)
  rescue => ex
    raise InvalidImageError, ex.message
  end
end

#resize!(geometry) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/imgry/processor/img_scalr.rb', line 22

def resize!(geometry)
  return if geometry.nil?
  new_width, new_height = Geometry.scale(width, height, geometry)

  @img = Scalr.resize(@img,
                      Scalr::Method::QUALITY,
                      Scalr::Mode::FIT_EXACT,
                      new_width, new_height)
end

#srcObject



18
19
20
# File 'lib/imgry/processor/img_scalr.rb', line 18

def src
  @img
end