Class: Spriteful::Image
- Inherits:
-
Object
- Object
- Spriteful::Image
- Defined in:
- lib/spriteful/image.rb
Overview
Internal: Data structure to represent the images that are part of a sprite.
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Public: returns the Image height in pixels.
-
#left ⇒ Object
Public: Gets/sets the left position of the image in a sprite.
-
#name ⇒ Object
readonly
Public: returns the filename of the Image.
-
#path ⇒ Object
readonly
Public: returns the path where the Image lives.
-
#source ⇒ Object
readonly
Public: Gets the source ‘Magick::Image’.
-
#top ⇒ Object
Public: Gets/sets the top position of the image in a sprite.
-
#width ⇒ Object
readonly
Public: returns the Image width in pixels.
Instance Method Summary collapse
-
#blob ⇒ Object
Public: Gets the source image contents.
-
#initialize(magick_image, optimize = true) ⇒ Image
constructor
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.
-
#svg? ⇒ Boolean
Public: detects if the source is a SVG image based on its path.
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
#height ⇒ Object (readonly)
Public: returns the Image height in pixels.
17 18 19 |
# File 'lib/spriteful/image.rb', line 17 def height @height end |
#left ⇒ Object
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 |
#name ⇒ Object (readonly)
Public: returns the filename of the Image.
11 12 13 |
# File 'lib/spriteful/image.rb', line 11 def name @name end |
#path ⇒ Object (readonly)
Public: returns the path where the Image lives.
8 9 10 |
# File 'lib/spriteful/image.rb', line 8 def path @path end |
#source ⇒ Object (readonly)
Public: Gets the source ‘Magick::Image’.
26 27 28 |
# File 'lib/spriteful/image.rb', line 26 def source @source end |
#top ⇒ Object
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 |
#width ⇒ Object (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
#blob ⇒ Object
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.
56 57 58 |
# File 'lib/spriteful/image.rb', line 56 def svg? File.extname(@path) == '.svg' end |