psd 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e77eb4145c66513958eb9d5c51cf3939106bcdd5
4
- data.tar.gz: 98cabd790e222e4162813293ea261786839e182a
3
+ metadata.gz: c100d128dba86088c063508116bc3a1acd0bd650
4
+ data.tar.gz: 042fe61f2579e7f7dfeda0e223abac81375908b4
5
5
  SHA512:
6
- metadata.gz: c070bad2a230a570d90014ae9b477d91f8c6b2928a54502fc217b647196cb48f96c4e27416cf351baee818bb310dcf93be3cd5993e081894490a6e4c81e2f611
7
- data.tar.gz: 54e63d06ae78fd5a87824ffa33c2f4e81acf9e73084d8d0068da10839ee9706dc366fdf8db8e1f14cd92ca895c26c30a042e9923533d668e445d118b310dbbf8
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 retrieves folder or layer nodes only by appending `_layers` or `_groups` to the method. For example:
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
@@ -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
- items_in_obj.times do |j|
126
- item << parse_object_array
127
- end
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
@@ -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
- @adjustments[name] = i
317
- info_parsed = true
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, IO::SEEK_CUR
328
+ @file.seek pos + length
325
329
  end
326
330
 
327
331
  @file.seek pos + length if @file.tell != (pos + length)
@@ -7,7 +7,6 @@ class PSD
7
7
  def parse
8
8
  # Useless id/version info
9
9
  @file.seek 12, IO::SEEK_CUR
10
-
11
10
  @data = Descriptor.new(@file).parse
12
11
  end
13
12
  end
@@ -1,3 +1,3 @@
1
1
  class PSD
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
@@ -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.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-30 00:00:00.000000000 Z
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
@@ -1,7 +0,0 @@
1
- require './lib/psd'
2
-
3
- psd = PSD.new('examples/images/example.psd')
4
- psd.parse!
5
-
6
-
7
- psd.export_node psd.tree.children.last.children[1], "asset.psd"
@@ -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
@@ -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
@@ -1,7 +0,0 @@
1
- require './lib/psd'
2
- require 'pp'
3
-
4
- psd = PSD.new('examples/images/example.psd')
5
- psd.parse!
6
-
7
- pp psd.tree.children_at_path("Version D/Version E/Version F").first.to_hash
@@ -1,8 +0,0 @@
1
- require './lib/psd'
2
- require 'pp'
3
-
4
- file = ARGV[0] || 'examples/images/example.psd'
5
- psd = PSD.new(file)
6
- psd.parse!
7
-
8
- pp psd.tree.to_hash
@@ -1,9 +0,0 @@
1
- require './lib/psd'
2
- require 'pp'
3
-
4
- file = ARGV[0] || 'examples/images/example.psd'
5
- psd = PSD.new(file)
6
- psd.parse!
7
-
8
- puts '-> Layer Info Keys'
9
- pp PSD.keys.uniq