psdlens 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/psdlens.rb +231 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bdac633df224cc6fb8cb837c2b96e8a73782a2e3
4
+ data.tar.gz: 4f089581ad86e734d7b593609933072b9fa1cb4c
5
+ SHA512:
6
+ metadata.gz: ebf2ba1143dd446252c385cb868e7892f3b7f0d22127a50b7bf4dd61a647a9c816ea5c95972ebdb813c30b87cab1db956b98f702ad078f3a6fa4152ad7793757
7
+ data.tar.gz: bf6df0e71271ab2c82a3c1fc4e2dae346d168ad6b8923fe2edd642da399482741eb9bc5c74108a9659fcdf76fd2a156c15f9823d03ddedaefe94267332000e5c
data/lib/psdlens.rb ADDED
@@ -0,0 +1,231 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'fileutils'
5
+ require 'psd'
6
+ require 'json'
7
+
8
+ puts "==================================="
9
+
10
+
11
+ # Create json reports for all PSD files
12
+ def globalReport(psdFiles, base)
13
+ psdFiles.each do |psdFile|
14
+ name = File.basename(psdFile, ".psd")
15
+ PSD.open(psdFile) do |psd|
16
+ content = psd.tree.to_hash
17
+ jsonContent = JSON.pretty_generate(content)
18
+ file = File.join(base, "#{name}.json")
19
+ File.open(file, "w") { |f| f.write(jsonContent) }
20
+ puts "[create] #{file}"
21
+ end
22
+ end
23
+ end
24
+
25
+
26
+ # Show all used fonts
27
+ def fontReport(psdFiles)
28
+ fontData = Array.new
29
+
30
+ psdFiles.each do |psdFile|
31
+ name = File.basename(psdFile)
32
+ PSD.open(psdFile) do |psd|
33
+ puts "\n[ #{name} ] Font used =================================== \n\n"
34
+ psd.layers.each do |layer|
35
+ fontRaw = layer.text
36
+ fontString = fontRaw.to_s()
37
+ fontstring = fontString.gsub!(':font=>{:name=>"', "spliter")
38
+ fontstring = fontString.gsub!('", :sizes=>[', "spliter")
39
+ fontArray = fontString.split("spliter")
40
+ fontName = fontArray[1].to_s()
41
+ if fontName == ""
42
+ else
43
+ fontData.push("* " + fontName)
44
+ end
45
+ end
46
+ end
47
+ fontDataClean = fontData.uniq
48
+ fontDataClean.each do |d|
49
+ puts d
50
+ end
51
+ end
52
+ end
53
+
54
+
55
+ # Extract text content from PSD and display font-size, font-family and color
56
+ def textReport(psdFiles)
57
+ textData = Array.new
58
+
59
+ psdFiles.each do |psdFile|
60
+ name = File.basename(psdFile)
61
+ PSD.open(psdFile) do |psd|
62
+ puts "\n[ #{name} ] Text Report =================================== \n\n"
63
+ psd.layers.each do |layer|
64
+ textRaw = layer.adjustments[:type]
65
+ textString = textRaw.to_s()
66
+
67
+ fontRaw = layer.text
68
+ fontString = fontRaw.to_s()
69
+ fontstring = fontString.gsub!(':font=>{:name=>"', "spliter")
70
+ fontstring = fontString.gsub!('", :sizes=>[', "spliter")
71
+ fontstring = fontString.gsub!('], :colors=>[', "spliter")
72
+ fontstring = fontString.gsub!(';\ncolor: ', "spliter")
73
+ fontstring = fontString.gsub!(';"}, :left=>', "spliter")
74
+ fontArray = fontString.split("spliter")
75
+
76
+ fontName = fontArray[1].to_s()
77
+ fontSize = fontArray[2].to_s()
78
+ fontColor = fontArray[4].to_s()
79
+
80
+ if textString == ""
81
+ else
82
+ textData.push("\n#{textString}\n=> #{fontName} | #{fontSize}px | #{fontColor}")
83
+ end
84
+ end
85
+ end
86
+ textDataClean = textData.uniq
87
+ textDataClean.each do |d|
88
+ puts d
89
+ end
90
+ end
91
+ end
92
+
93
+
94
+ # Extract text content from PSD
95
+ def contentReport(psdFiles)
96
+ textData = Array.new
97
+
98
+ psdFiles.each do |psdFile|
99
+ name = File.basename(psdFile)
100
+ PSD.open(psdFile) do |psd|
101
+ puts "\n[ #{name} ] Text Content =================================== \n\n"
102
+ psd.layers.each do |layer|
103
+ textRaw = layer.adjustments[:type]
104
+ textString = textRaw.to_s()
105
+ if textString == ""
106
+ else
107
+ textData.push("\n#{textString}\n")
108
+ end
109
+ end
110
+ end
111
+ textDataClean = textData.uniq
112
+ textDataClean.each do |d|
113
+ puts d
114
+ end
115
+ end
116
+ end
117
+
118
+
119
+ def metaReport(psdFiles)
120
+ fontData = Array.new
121
+
122
+ psdFiles.each do |psdFile|
123
+ name = File.basename(psdFile)
124
+ PSD.open(psdFile) do |psd|
125
+ puts "\n[ #{name} ] Meta report =================================== \n\n"
126
+ psdWidth = psd.width
127
+ psdHeight = psd.height
128
+ psdLayers = psd.layers.size
129
+ psdGroup = psd.folders.size
130
+ psdMode = psd.header.mode_name
131
+ psd.layers.each do |layer|
132
+ fontRaw = layer.text
133
+ fontString = fontRaw.to_s()
134
+ fontArray = fontString.split(':font=>{:name=>"')
135
+ fontFirstPart = fontArray[1].to_s()
136
+ fontNameArray = fontFirstPart.split('", :sizes=>[')
137
+ fontName = fontNameArray[0].to_s()
138
+ if fontName == ""
139
+ else
140
+ fontData.push(fontName)
141
+ end
142
+ end
143
+ fontDataClean = fontData.uniq
144
+ psdFonts = fontDataClean.to_s().tr('[]""', '')
145
+ puts "Document size : #{psdWidth}px x #{psdHeight}px"
146
+ puts "Color mode : #{psdMode}"
147
+ puts "Content : #{psdLayers} layers in #{psdGroup} groups"
148
+ puts "Fonts : #{psdFonts}"
149
+ end
150
+ end
151
+ end
152
+
153
+
154
+ # Parse options and creat doc
155
+ OptionParser.new do |opts|
156
+ opts.banner = "
157
+ Usage: #{File.basename($0)} [path] [method]
158
+
159
+ [path] : Absolute path or current location using .
160
+
161
+ [method] :
162
+
163
+ * meta Display all informations like size, color mode or used fontString
164
+ * text Display text content from all PSD files and return font-family, font-size and color
165
+ * font Display only used font
166
+ * content Display only text conent
167
+ * report Create a complete json report for all PSD
168
+
169
+ Example : #{File.basename($0)} . meta
170
+
171
+ "
172
+ begin
173
+ opts.parse!(ARGV)
174
+ rescue OptionParser::ParseError => e
175
+ warn e.message
176
+ puts opts
177
+ exit 1
178
+ end
179
+ end
180
+
181
+ if ARGV.empty?
182
+ abort "[error] Please specify the PSD directory to parse, e.g. `#{File.basename($0)} .'"
183
+ elsif !File.exists?(ARGV[0])
184
+ abort "[error] '#{ARGV[0]}' does not exist.\n\n"
185
+ elsif !File.directory?(ARGV[0])
186
+ abort "[error] '#{ARGV[0]}' is not a directory."
187
+ end
188
+
189
+ path = ARGV[0]
190
+ methodArg = ARGV[1]
191
+
192
+ currentPath = Dir.pwd + "/"
193
+ base = path == "." ? currentPath : path + "/"
194
+ psdFiles = Dir[base+"*.psd"]
195
+
196
+ beginMessage = "[start] Begin PSD analysis ...\n\n"
197
+
198
+
199
+ case methodArg
200
+ when "meta"
201
+ puts beginMessage
202
+ metaReport(psdFiles)
203
+ when "text"
204
+ puts beginMessage
205
+ textReport(psdFiles)
206
+ when "content"
207
+ puts beginMessage
208
+ contentReport(psdFiles)
209
+ when "font"
210
+ puts beginMessage
211
+ fontReport(psdFiles)
212
+ when "report"
213
+ puts beginMessage
214
+ globalReport(psdFiles, base)
215
+ else
216
+ abort "\n[error] no correct method select\n\n"
217
+ end
218
+
219
+
220
+ puts "\n\n[done] PSD well analyzed !\n\n"
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: psdlens
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yann Gouffon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple tool to analyze Photoshop files directly command line
14
+ email: hello@yago.io
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/psdlens.rb
20
+ homepage: https://github.com/Yago31/psdlens
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.0.0
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: PSD analyzer tool
44
+ test_files: []