Class: PsdToSprite::SpriteMaker
- Inherits:
-
Object
- Object
- PsdToSprite::SpriteMaker
- Defined in:
- lib/psd_to_sprite.rb
Instance Attribute Summary collapse
-
#frame_height ⇒ Object
readonly
Returns the value of attribute frame_height.
-
#frame_width ⇒ Object
readonly
Returns the value of attribute frame_width.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#psd ⇒ Object
readonly
Returns the value of attribute psd.
Instance Method Summary collapse
-
#initialize(psd_path) ⇒ SpriteMaker
constructor
A new instance of SpriteMaker.
- #process(output_path = nil) ⇒ Object
Constructor Details
#initialize(psd_path) ⇒ SpriteMaker
Returns a new instance of SpriteMaker.
10 11 12 13 |
# File 'lib/psd_to_sprite.rb', line 10 def initialize(psd_path) @path = Pathname.new(psd_path) @psd = PSD.new(psd_path) end |
Instance Attribute Details
#frame_height ⇒ Object (readonly)
Returns the value of attribute frame_height.
8 9 10 |
# File 'lib/psd_to_sprite.rb', line 8 def frame_height @frame_height end |
#frame_width ⇒ Object (readonly)
Returns the value of attribute frame_width.
8 9 10 |
# File 'lib/psd_to_sprite.rb', line 8 def frame_width @frame_width end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/psd_to_sprite.rb', line 8 def path @path end |
#psd ⇒ Object (readonly)
Returns the value of attribute psd.
8 9 10 |
# File 'lib/psd_to_sprite.rb', line 8 def psd @psd end |
Instance Method Details
#process(output_path = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/psd_to_sprite.rb', line 15 def process(output_path = nil) psd.parse! root_node = psd.tree @frame_height = root_node.height @frame_width = root_node.width output_width = root_node.children.count * frame_width pngs = collect_pngs_from_layers(root_node.children) img = save_pngs_to_new_image(pngs, output_width, frame_height) return img.write(output_path) if output_path img.write("#{path.dirname}/#{filename_without_ext}.png") end |