psd 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/psd/descriptor.rb +28 -7
- data/lib/psd/layer.rb +10 -6
- data/lib/psd/layer_info/placed_layer.rb +0 -1
- data/lib/psd/version.rb +1 -1
- data/psd.gemspec +1 -1
- metadata +2 -13
- data/examples/export.rb +0 -7
- data/examples/export_image.rb +0 -12
- data/examples/export_text_data.rb +0 -13
- data/examples/images/example-cmyk.psd +0 -0
- data/examples/images/example-greyscale.psd +0 -0
- data/examples/images/example.psd +0 -0
- data/examples/images/example16.psd +0 -0
- data/examples/parse.rb +0 -31
- data/examples/path.rb +0 -7
- data/examples/tree.rb +0 -8
- data/examples/unimplemented_info.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c100d128dba86088c063508116bc3a1acd0bd650
|
4
|
+
data.tar.gz: 042fe61f2579e7f7dfeda0e223abac81375908b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f261b03bea18d788a5d3c608fdb4c41886a2f76030ee4d670a21ae03305940fd610743ea089bcde1c5dd15643b464b7655f591e592950020fd80151547963288
|
7
|
+
data.tar.gz: 3547fe009db381c5e0286c2e7a66e14944388f02591436d20cef0c4d470c4b4cf870bcd105a793aa44cf0d3d38880a2be52f893d49eb4ed40ef310d8dd640b96
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# PSD.rb
|
2
2
|
|
3
|
-
![](https://circleci.com/gh/layervault/psd.rb.png?circle-token=ad8a75fdd86f595e0926a963179a3a621d564c6e)
|
3
|
+
[![Circle CI](https://circleci.com/gh/layervault/psd.rb.png?circle-token=ad8a75fdd86f595e0926a963179a3a621d564c6e)](https://circleci.com/gh/layervault/psd.rb)
|
4
4
|
|
5
5
|
A general purpose Photoshop file parser written in Ruby. It allows you to work with a Photoshop document in a manageable tree structure and find out important data such as:
|
6
6
|
|
@@ -52,7 +52,7 @@ To access the document as a tree structure, use `psd.tree` to get the root node.
|
|
52
52
|
* `subtree`: same as descendants but starts with the current node
|
53
53
|
* `depth`: calculate the depth of the current node
|
54
54
|
|
55
|
-
For any of the traversal methods, you can also
|
55
|
+
For any of the traversal methods, you can also retrieve folder or layer nodes only by appending `_layers` or `_groups` to the method. For example:
|
56
56
|
|
57
57
|
``` ruby
|
58
58
|
psd.tree.descendant_layers
|
data/lib/psd/descriptor.rb
CHANGED
@@ -64,6 +64,7 @@ class PSD
|
|
64
64
|
when 'obj ' then parse_reference
|
65
65
|
when 'TEXT' then @file.read_unicode_string
|
66
66
|
when 'UntF' then parse_unit_double
|
67
|
+
when 'UnFl' then parse_unit_float
|
67
68
|
end
|
68
69
|
|
69
70
|
return value
|
@@ -115,18 +116,21 @@ class PSD
|
|
115
116
|
end
|
116
117
|
|
117
118
|
def parse_object_array
|
119
|
+
raise NotImplementedError.new("Object array not implemented yet")
|
118
120
|
count = @file.read_int
|
119
|
-
klass = parse_class
|
120
121
|
items_in_obj = @file.read_int
|
122
|
+
wat = @file.read_short
|
123
|
+
|
124
|
+
puts count
|
125
|
+
puts items_in_obj
|
126
|
+
puts wat
|
121
127
|
|
122
|
-
obj =
|
128
|
+
obj = {}
|
123
129
|
count.times do |i|
|
124
130
|
item = []
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
obj << item
|
131
|
+
name = @file.read_string(@file.read_int)
|
132
|
+
puts name
|
133
|
+
obj[name] = parse_list
|
130
134
|
end
|
131
135
|
|
132
136
|
return obj
|
@@ -168,5 +172,22 @@ class PSD
|
|
168
172
|
value = @file.read_double
|
169
173
|
{id: unit_id, unit: unit, value: value}
|
170
174
|
end
|
175
|
+
|
176
|
+
def parse_unit_float
|
177
|
+
unit_id = @file.read_string(4)
|
178
|
+
unit = case unit_id
|
179
|
+
when '#Ang' then 'Angle'
|
180
|
+
when '#Rsl' then 'Density'
|
181
|
+
when '#Rlt' then 'Distance'
|
182
|
+
when '#Nne' then 'None'
|
183
|
+
when '#Prc' then 'Percent'
|
184
|
+
when '#Pxl' then 'Pixels'
|
185
|
+
when '#Mlm' then 'Millimeters'
|
186
|
+
when '#Pnt' then 'Points'
|
187
|
+
end
|
188
|
+
|
189
|
+
value = @file.read_float
|
190
|
+
{id: unit_id, unit: unit, value: value}
|
191
|
+
end
|
171
192
|
end
|
172
193
|
end
|
data/lib/psd/layer.rb
CHANGED
@@ -309,19 +309,23 @@ class PSD
|
|
309
309
|
info_parsed = false
|
310
310
|
LAYER_INFO.each do |name, info|
|
311
311
|
next unless info.key == key
|
312
|
-
|
313
|
-
i = info.new(@file, length)
|
314
|
-
i.parse
|
315
312
|
|
316
|
-
|
317
|
-
|
313
|
+
begin
|
314
|
+
i = info.new(@file, length)
|
315
|
+
i.parse
|
316
|
+
|
317
|
+
@adjustments[name] = i
|
318
|
+
info_parsed = true
|
319
|
+
rescue Exception
|
320
|
+
end
|
321
|
+
|
318
322
|
break
|
319
323
|
end
|
320
324
|
|
321
325
|
if !info_parsed
|
322
326
|
PSD.keys << key
|
323
327
|
# puts "SKIPPING #{key}, length = #{length}"
|
324
|
-
@file.seek length
|
328
|
+
@file.seek pos + length
|
325
329
|
end
|
326
330
|
|
327
331
|
@file.seek pos + length if @file.tell != (pos + length)
|
data/lib/psd/version.rb
CHANGED
data/psd.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.homepage = "http://cosmos.layervault.com/psdrb.html"
|
14
14
|
gem.license = 'MIT'
|
15
15
|
|
16
|
-
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.files = `git ls-files`.split($/).delete_if { |f| f.include?('examples/') }
|
17
17
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: psd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan LeFevre
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bindata
|
@@ -125,17 +125,6 @@ files:
|
|
125
125
|
- README.md
|
126
126
|
- Rakefile
|
127
127
|
- circle.yml
|
128
|
-
- examples/export.rb
|
129
|
-
- examples/export_image.rb
|
130
|
-
- examples/export_text_data.rb
|
131
|
-
- examples/images/example-cmyk.psd
|
132
|
-
- examples/images/example-greyscale.psd
|
133
|
-
- examples/images/example.psd
|
134
|
-
- examples/images/example16.psd
|
135
|
-
- examples/parse.rb
|
136
|
-
- examples/path.rb
|
137
|
-
- examples/tree.rb
|
138
|
-
- examples/unimplemented_info.rb
|
139
128
|
- lib/psd.rb
|
140
129
|
- lib/psd/blend_mode.rb
|
141
130
|
- lib/psd/channel_image.rb
|
data/examples/export.rb
DELETED
data/examples/export_image.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'benchmark'
|
2
|
-
require './lib/psd'
|
3
|
-
|
4
|
-
psd = PSD.new('examples/images/example.psd')
|
5
|
-
|
6
|
-
results = Benchmark.measure "Image exporting" do
|
7
|
-
psd.image.save_as_png 'output.png'
|
8
|
-
end
|
9
|
-
|
10
|
-
puts "Flattened image exported to ./output.png\n"
|
11
|
-
puts Benchmark::CAPTION
|
12
|
-
puts results.to_s
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require './lib/psd'
|
2
|
-
|
3
|
-
file = ARGV[0] || 'examples/images/example.psd'
|
4
|
-
psd = PSD.new(file)
|
5
|
-
psd.parse!
|
6
|
-
|
7
|
-
outfile = './enginedata'
|
8
|
-
psd.tree.descendant_layers.each do |l|
|
9
|
-
next unless l.layer.adjustments[:type]
|
10
|
-
File.write(outfile, l.layer.adjustments[:type].engine_data)
|
11
|
-
puts "Exported to #{outfile}"
|
12
|
-
exit
|
13
|
-
end
|
Binary file
|
Binary file
|
data/examples/images/example.psd
DELETED
Binary file
|
Binary file
|
data/examples/parse.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'benchmark'
|
2
|
-
require './lib/psd'
|
3
|
-
|
4
|
-
psd = nil
|
5
|
-
file = ARGV[0] || 'examples/images/example.psd'
|
6
|
-
results = Benchmark.measure "PSD parsing" do
|
7
|
-
psd = PSD.new(file)
|
8
|
-
psd.parse!
|
9
|
-
end
|
10
|
-
|
11
|
-
puts "\nVisible Layers:\n===================="
|
12
|
-
psd.layers.each do |layer|
|
13
|
-
next if layer.folder? || layer.hidden?
|
14
|
-
|
15
|
-
puts "Name: #{layer.name}"
|
16
|
-
puts "Position: top = #{layer.top}, left = #{layer.left}"
|
17
|
-
puts "Size: width = #{layer.width}, height = #{layer.height}"
|
18
|
-
puts "Mask: width = #{layer.mask.width}, height = #{layer.mask.height}"
|
19
|
-
puts "Reference point: #{layer.ref_x}, #{layer.ref_y}"
|
20
|
-
|
21
|
-
puts ""
|
22
|
-
end
|
23
|
-
|
24
|
-
puts "\nPSD Info:\n===================="
|
25
|
-
puts "#{psd.width}x#{psd.height} #{psd.header.mode_name}"
|
26
|
-
puts "#{psd.resources.size} resources parsed"
|
27
|
-
puts "#{psd.layers.size} layers, #{psd.folders.size} folders"
|
28
|
-
|
29
|
-
puts "\nBenchmark Results (seconds):\n===================="
|
30
|
-
puts " "*7 + Benchmark::CAPTION
|
31
|
-
puts "parse: " + results.to_s
|
data/examples/path.rb
DELETED
data/examples/tree.rb
DELETED