psd_to_sprite 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/Rakefile +2 -0
- data/example/example.png +0 -0
- data/example/example.psd +0 -0
- data/lib/psd_to_sprite.rb +59 -0
- data/lib/psd_to_sprite/version.rb +3 -0
- data/psd_to_sprite.gemspec +30 -0
- data/spec/psd_to_sprite/sprite_maker_spec.rb +47 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/support/example.psd +0 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f0216dead5623252fbb7623b0442dbc2657e70c2
|
4
|
+
data.tar.gz: 0fb377da4b4d0bce98ed907431aef8621df72458
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7d9e8bae968dea87864b37c68035141f9193bc174e6c2e5f8bb3f10a24093617f232f5dd0bd8121750b1e3f6d9d0bab22f1f469e54a5e0760585f8069ad5fd78
|
7
|
+
data.tar.gz: 04685ce38b77cb60a75ea1092f688a627cbad8a348ddf79dfcd760bff5d6e2b20e6782434b1ddf0b5097eb71e623a9f5e55de37916d6cf7ffbb86581c3c81e36
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Carl Furrow
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# PsdToSprite
|
2
|
+
|
3
|
+
Convert a PSD with layers to a single sprite sheet for animations
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'psd_to_sprite'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install psd_to_sprite
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
This gem takes a Photoshop file (PSD) that has layers, all the same size, and outputs
|
24
|
+
each layer into a horizontal sprite sheet, with each layer laid next to the other,
|
25
|
+
left to right. The ordering of the layers in your PSD will dictate the ordering
|
26
|
+
of the sprites in the output png. The layer at the very bottom will become frame 0,
|
27
|
+
the next one frame 1, and so on.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'psd_to_sprite'
|
31
|
+
|
32
|
+
sprite_maker = PsdToSprite::SpriteMaker.new("example.psd")
|
33
|
+
sprite_maker.process # => outputs to example.png
|
34
|
+
sprite_maker.process("foo.png") #=> outputs to foo.png
|
35
|
+
```
|
36
|
+
|
37
|
+
### Output example
|
38
|
+
|
39
|
+
*Note: Example image comes from the [Phaser.js](http://phaser.io/) project*
|
40
|
+
|
41
|
+
![example](example/example.png)
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it ( https://github.com/[my-github-username]/psd_to_sprite/fork )
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Write specs
|
48
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
6. Create a new Pull Request
|
data/Rakefile
ADDED
data/example/example.png
ADDED
Binary file
|
data/example/example.psd
ADDED
Binary file
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'psd_to_sprite/version'
|
2
|
+
require 'pathname'
|
3
|
+
require 'psd'
|
4
|
+
require 'rmagick'
|
5
|
+
|
6
|
+
module PsdToSprite
|
7
|
+
class SpriteMaker
|
8
|
+
attr_reader :frame_width, :frame_height, :path, :psd
|
9
|
+
|
10
|
+
def initialize(psd_path)
|
11
|
+
@path = Pathname.new(psd_path)
|
12
|
+
@psd = PSD.new(psd_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def process(output_path = nil)
|
16
|
+
psd.parse!
|
17
|
+
root_node = psd.tree
|
18
|
+
@frame_height = root_node.height
|
19
|
+
@frame_width = root_node.width
|
20
|
+
|
21
|
+
output_width = root_node.children.count * frame_width
|
22
|
+
|
23
|
+
pngs = collect_pngs_from_layers(root_node.children)
|
24
|
+
img = save_pngs_to_new_image(pngs, output_width, frame_height)
|
25
|
+
|
26
|
+
return img.write(output_path) if output_path
|
27
|
+
img.write("#{path.dirname}/#{filename_without_ext}.png")
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def filename_without_ext
|
32
|
+
path.basename.to_s.gsub(path.extname, "")
|
33
|
+
end
|
34
|
+
|
35
|
+
def collect_pngs_from_layers(layers)
|
36
|
+
pngs = []
|
37
|
+
layers.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)
|
44
|
+
img = Magick::Image.new(output_width, output_height) do
|
45
|
+
self.background_color = "transparent"
|
46
|
+
end
|
47
|
+
|
48
|
+
x = 0
|
49
|
+
y = 0
|
50
|
+
|
51
|
+
pngs.each do |frame|
|
52
|
+
frame_img = Magick::Image.from_blob(frame.to_s).first
|
53
|
+
img = img.composite(frame_img, x, y, Magick::AddCompositeOp)
|
54
|
+
x += frame_width
|
55
|
+
end
|
56
|
+
img
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'psd_to_sprite/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "psd_to_sprite"
|
8
|
+
spec.version = PsdToSprite::VERSION
|
9
|
+
spec.authors = ["Carl Furrow"]
|
10
|
+
spec.email = ["carl.furrow@gmail.com"]
|
11
|
+
spec.summary = %q{Convert a PSD with layers to a single sprite sheet for animations}
|
12
|
+
spec.description = %q{Take a psd with layers, one for each frame, and output to a single png file with each frame placed next to the other in order of the layers in the psd.}
|
13
|
+
spec.homepage = "http://github.com/cfurrow/psd_to_sprite"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
|
22
|
+
spec.add_dependency "rmagick", "~> 2.13"
|
23
|
+
spec.add_dependency "psd", "~> 3.2"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
spec.add_development_dependency "pry-nav"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module PsdToSprite
|
4
|
+
describe SpriteMaker do
|
5
|
+
PATH_TO_PNG = "spec/support/example.png"
|
6
|
+
LAYER_COUNT = 13
|
7
|
+
FRAME_WIDTH = 32
|
8
|
+
FRAME_HEIGHT = 48
|
9
|
+
|
10
|
+
let(:psd_path) { '' }
|
11
|
+
let(:maker) { SpriteMaker.new(psd_path) }
|
12
|
+
|
13
|
+
describe "#process" do
|
14
|
+
subject { maker.process }
|
15
|
+
|
16
|
+
context "when psd does not exist" do
|
17
|
+
it "fails hard" do
|
18
|
+
expect { subject }.to raise_error
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when psd does exist" do
|
23
|
+
let(:psd_path) { 'spec/support/example.psd' }
|
24
|
+
let(:output_image) { Magick::Image.read(PATH_TO_PNG).first }
|
25
|
+
|
26
|
+
it "does not fail hard" do
|
27
|
+
expect { subject }.to_not raise_error
|
28
|
+
end
|
29
|
+
|
30
|
+
it "creates example.png" do
|
31
|
+
path = Pathname.new(PATH_TO_PNG)
|
32
|
+
expect { subject }.to change { path.exist? }.to(true).from(false)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "creates an output image wide enough for all frames" do
|
36
|
+
subject
|
37
|
+
expect(output_image.base_columns).to eq(LAYER_COUNT * FRAME_WIDTH)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "creates an output file with a height of the input frame file" do
|
41
|
+
subject
|
42
|
+
expect(output_image.base_rows).to eq(FRAME_HEIGHT)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: psd_to_sprite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carl Furrow
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rmagick
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.13'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: psd
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-nav
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
description: Take a psd with layers, one for each frame, and output to a single png
|
112
|
+
file with each frame placed next to the other in order of the layers in the psd.
|
113
|
+
email:
|
114
|
+
- carl.furrow@gmail.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- example/example.png
|
125
|
+
- example/example.psd
|
126
|
+
- lib/psd_to_sprite.rb
|
127
|
+
- lib/psd_to_sprite/version.rb
|
128
|
+
- psd_to_sprite.gemspec
|
129
|
+
- spec/psd_to_sprite/sprite_maker_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
- spec/support/example.psd
|
132
|
+
homepage: http://github.com/cfurrow/psd_to_sprite
|
133
|
+
licenses:
|
134
|
+
- MIT
|
135
|
+
metadata: {}
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
requirements: []
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 2.2.2
|
153
|
+
signing_key:
|
154
|
+
specification_version: 4
|
155
|
+
summary: Convert a PSD with layers to a single sprite sheet for animations
|
156
|
+
test_files:
|
157
|
+
- spec/psd_to_sprite/sprite_maker_spec.rb
|
158
|
+
- spec/spec_helper.rb
|
159
|
+
- spec/support/example.psd
|