psd_to_sprite 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd7e5b0e09390fb67b41f2aa95192bcb8c17d057
4
- data.tar.gz: 5170aee3b7ffc253d795837ecc3c6abd7992c3c9
3
+ metadata.gz: d332c55c30ca6361652a65f44537414677f5ae9e
4
+ data.tar.gz: 578ef314efd9314e703e7b74a498f506cacc45cd
5
5
  SHA512:
6
- metadata.gz: 2427ffd308343e26d089ca12e1fd57ef06ec7bd900a8ca13384ba2832e8b914fcdc4ab81e4cda60f75ded77005702ba80a7b389f8876b8fa5b33c74cc629855f
7
- data.tar.gz: d907d879c0158e15b946ce60de180df0f717fe6b0ee4e361fae693e9a355039e5ccd9e117ec5451fa999e0da887a22f459b3e1029ab29c4aedb2b96b58ad6cd6
6
+ metadata.gz: 84aecf24b9654c1f3e0a308f9a0612f0160033998168d3a7047a56f99cc9746a8c220b1b8e54d7b3814e83715a4ec46e190d07da04f5a3bb364670727a86e000
7
+ data.tar.gz: 3acbea4aeedd0d0af493af0910fe7194f790ab8d2a6b23eae8f6566ffc6d3b3645c1eee3d6ac44f7b8157f24ed7dd40b0fc11ed748b9b8efea56a0d6198f546d
@@ -1,3 +1,3 @@
1
1
  module PsdToSprite
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/psd_to_sprite.rb CHANGED
@@ -5,7 +5,7 @@ require 'rmagick'
5
5
 
6
6
  module PsdToSprite
7
7
  class SpriteMaker
8
- attr_reader :frame_width, :frame_height, :path, :psd
8
+ attr_reader :frame_width, :frame_height, :layers, :path, :psd
9
9
 
10
10
  def initialize(psd_path)
11
11
  @path = Pathname.new(psd_path)
@@ -17,11 +17,11 @@ module PsdToSprite
17
17
  root_node = psd.tree
18
18
  @frame_height = root_node.height
19
19
  @frame_width = root_node.width
20
+ @layers = psd.layers
20
21
 
21
22
  output_width = root_node.children.count * frame_width
22
23
 
23
- pngs = collect_pngs_from_layers(root_node.children)
24
- img = save_pngs_to_new_image(pngs, output_width, frame_height)
24
+ img = save_layers_to_new_image(output_width, frame_height)
25
25
 
26
26
  return img.write(output_path) if output_path
27
27
  img.write("#{path.dirname}/#{filename_without_ext}.png")
@@ -32,15 +32,7 @@ module PsdToSprite
32
32
  path.basename.to_s.gsub(path.extname, "")
33
33
  end
34
34
 
35
- def collect_pngs_from_layers(layers)
36
- pngs = []
37
- layers.reverse.each do |layer|
38
- pngs << layer.to_png
39
- end
40
- pngs
41
- end
42
-
43
- def save_pngs_to_new_image(pngs, output_width, output_height)
35
+ def save_layers_to_new_image(output_width, output_height)
44
36
  img = Magick::Image.new(output_width, output_height) do
45
37
  self.background_color = "transparent"
46
38
  end
@@ -48,9 +40,11 @@ module PsdToSprite
48
40
  x = 0
49
41
  y = 0
50
42
 
51
- pngs.each do |frame|
43
+ layers.reverse.each do |layer|
44
+ frame = layer.image.to_png
52
45
  frame_img = Magick::Image.from_blob(frame.to_s).first
53
- img = img.composite(frame_img, x, y, Magick::AddCompositeOp)
46
+
47
+ img = img.composite(frame_img, x, layer.top, Magick::AddCompositeOp)
54
48
  x += frame_width
55
49
  end
56
50
  img
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: psd_to_sprite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Furrow