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 +4 -4
- data/lib/psd_to_sprite/version.rb +1 -1
- data/lib/psd_to_sprite.rb +8 -14
- data/spec/support/example.psd +0 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d332c55c30ca6361652a65f44537414677f5ae9e
|
4
|
+
data.tar.gz: 578ef314efd9314e703e7b74a498f506cacc45cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84aecf24b9654c1f3e0a308f9a0612f0160033998168d3a7047a56f99cc9746a8c220b1b8e54d7b3814e83715a4ec46e190d07da04f5a3bb364670727a86e000
|
7
|
+
data.tar.gz: 3acbea4aeedd0d0af493af0910fe7194f790ab8d2a6b23eae8f6566ffc6d3b3645c1eee3d6ac44f7b8157f24ed7dd40b0fc11ed748b9b8efea56a0d6198f546d
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
46
|
+
|
47
|
+
img = img.composite(frame_img, x, layer.top, Magick::AddCompositeOp)
|
54
48
|
x += frame_width
|
55
49
|
end
|
56
50
|
img
|
data/spec/support/example.psd
CHANGED
Binary file
|