Class: Gastly::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/gastly/image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image) ⇒ Image

Returns a new instance of Image.

Parameters:

  • image (MiniMagick::Image)

    Instance of MiniMagick::Image



6
7
8
# File 'lib/gastly/image.rb', line 6

def initialize(image)
  @image = image
end

Instance Attribute Details

#imageObject (readonly)

Returns the value of attribute image.



3
4
5
# File 'lib/gastly/image.rb', line 3

def image
  @image
end

Instance Method Details

#crop(width:, height:, x:, y:) ⇒ Object

Parameters:

  • width (Fixnum)

    Crop width

  • height (Fixnum)

    Crop height

  • x (Fixnum)

    Crop x offset

  • y (Fixnum)

    Crop y offset



21
22
23
24
# File 'lib/gastly/image.rb', line 21

def crop(width:, height:, x:, y:)
  dimensions = "#{width}x#{height}+#{x}+#{y}"
  image.crop(dimensions)
end

#format(ext) ⇒ MiniMagick::Image

Returns Instance.

Parameters:

  • ext (String)

    Image extension

Returns:

  • (MiniMagick::Image)

    Instance



28
29
30
# File 'lib/gastly/image.rb', line 28

def format(ext)
  image.format(ext)
end

#resize(width:, height:) ⇒ Object

Parameters:

  • width (Fixnum)

    Image width

  • height (Fixnum)

    Image height



12
13
14
15
# File 'lib/gastly/image.rb', line 12

def resize(width:, height:)
  dimensions = "#{width}x#{height}"
  image.resize(dimensions)
end

#save(output) ⇒ String

Returns Full path to image.

Parameters:

  • output (String)

    Full path to image

Returns:

  • (String)

    Full path to image



34
35
36
37
# File 'lib/gastly/image.rb', line 34

def save(output)
  image.write(output)
  output
end