Class: Spriteful::Image

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

Overview

Internal: Data structure to represent the images that are part of a sprite.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(magick_image, optimize = true) ⇒ Image

Public: Initializes an Image, extracting the image metadata such as width and path supplied by an ‘Magick::Image’ object that was initialized from the real image blob.

magick_image - an ‘Magick::Image’ object.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/spriteful/image.rb', line 33

def initialize(magick_image, optimize=true)
  @source = magick_image
  @path   = magick_image.base_filename
  @name   = File.basename(@path)
  @width  = magick_image.columns
  @height = magick_image.rows
  @optimize = optimize

  @top    = 0
  @left   = 0
end

Instance Attribute Details

#heightObject (readonly)

Public: returns the Image height in pixels.



17
18
19
# File 'lib/spriteful/image.rb', line 17

def height
  @height
end

#leftObject

Public: Gets/sets the left position of the image in a sprite.



23
24
25
# File 'lib/spriteful/image.rb', line 23

def left
  @left
end

#nameObject (readonly)

Public: returns the filename of the Image.



11
12
13
# File 'lib/spriteful/image.rb', line 11

def name
  @name
end

#pathObject (readonly)

Public: returns the path where the Image lives.



8
9
10
# File 'lib/spriteful/image.rb', line 8

def path
  @path
end

#sourceObject (readonly)

Public: Gets the source ‘Magick::Image’.



26
27
28
# File 'lib/spriteful/image.rb', line 26

def source
  @source
end

#topObject

Public: Gets/sets the top position of the image in a sprite.



20
21
22
# File 'lib/spriteful/image.rb', line 20

def top
  @top
end

#widthObject (readonly)

Public: returns the Image width in pixels.



14
15
16
# File 'lib/spriteful/image.rb', line 14

def width
  @width
end

Instance Method Details

#blobObject

Public: Gets the source image contents.

Returns a String.



48
49
50
# File 'lib/spriteful/image.rb', line 48

def blob
  @blob ||= read_blob
end

#svg?Boolean

Public: detects if the source is a SVG image based on its path.

Returns true or false.

Returns:

  • (Boolean)


56
57
58
# File 'lib/spriteful/image.rb', line 56

def svg?
  File.extname(@path) == '.svg'
end