:note

psd.rb でPhotoshopドキュメント内の使用フォントを調べる

Photoshopドキュメント内の使用フォントを確認するのに psd.rb を使って試した

layervault/psd.rb

時間がなかったのでずるしたけど、

layervault/psd-enginedata

でFontData抜くのが正当なんだと思う

インストール

gem install psd

使用フォントの確認とjson書き出し

# -*- coding: utf-8 -*-
require "psd"
require "json"

path = '/path/to/psd.psd'

hash = PSD.open(path) do |psd|
  psd.tree.to_hash
end

hash.keys # [:children, :document]

hash[:document] # {:width=>1920, :height=>4500, :resources=>{:layer_comps=>[], :guides=>[{:location=>460, :direction=>"vertical"}, {:location=>1460, :direction=>"vertical"}, {:location=>550, :direction=>"horizontal"}, {:location=>2092, :direction=>"vertical"}, {:location=>2091, :direction=>"vertical"}, {:location=>1210, :direction=>"horizontal"}, {:location=>510, :direction=>"vertical"}, {:location=>525, :direction=>"vertical"}, {:location=>1410, :direction=>"vertical"}, {:location=>1395, :direction=>"vertical"}, {:location=>960, :direction=>"vertical"}], :slices=>[{:id=>0, :group_id=>0, :origin=>"autoGenerated", :associated_layer_id=>nil, :name=>"", :type=>"Img ", :bounds=>{:left=>0, :top=>0, :right=>1920, :bottom=>4500}, :url=>"", :target=>"", :message=>"", :alt=>"", :cell_text_is_html=>true, :cell_text=>"", :horizontal_alignment=>"default", :vertical_alignment=>"default", :color=>nil, :outset=>{:top=>0, :left=>0, :bottom=>0, :right=>0}}]}}
hash[:children] # "[{:type=>:group, :visible=>false, :opacity=>1.0, :blending_mode=>\"passthru\", :name=>\"グループ1\", :left=>-109, :right=>1920, :top=>-155, :bottom=>2300, :height=>2455, :width=>2029, :children=>[{:type=>:group, :visible=>true, :opacity=>1.0, :blending_mode=>\"passthru\", :name=>\"あ icon\", :left=>694, :right=>1285, :top=>328, :bottom=>656, :height=>328, :width=>591, :children=>[{:type=>:layer, :visible=>true, :opacity=>1.0, :blending_mode=>\"normal\", :name=>\"あ pict\", :left=>773, :right=>811, :top=>463, :bottom=>512, :height=>49, :width=>38, :text=>nil, :ref_x=>775.0, :ref_y=>465.0, :mask=>{}, :image=>{:width=>38, :height=>49, :channels=>[{:id=>-1, :length=>841}, {:id=>0, :length=>1197}, {:id=>1, :length=>1240}, {:id=>2, :length=>1117}]}}, {:type=>:layer, :visible=>true, :opacity=>1.0, :blending_mode=>\"normal\", :name=>\"あ pict 8\", :left=>715, :right=>753, :top=>607, :bottom=>656, :height=>49, :width=>38, :text=>nil, :ref_x=>717.0, :ref_y=>609.0, :mask=>{}, :image=>{"........

File.open(File.expand_path("~/Desktop/psd.json"), "w") do |file|
  file.print hash[:children].to_json
end

puts hash[:children].to_s.scan(/(?<=\:font\=>\{\:name=>\")[^\"]+/).uniq.sort

使用箇所の確認用にjson書き出してみたところ、layerオブジェクトのtext.valueが文字化けするっぽい

Non English character in text layer · Issue #56 · layervault/psd.rb

 
comments powered by Disqus
back to top