Skip to content

Commit

Permalink
Merge pull request #93 from redcap97/resolution_info
Browse files Browse the repository at this point in the history
added support for ResolutionInfo
  • Loading branch information
meltingice committed Feb 14, 2016
2 parents c15bdd7 + f234001 commit 31c7ddd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/psd/resources/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ def name; self.class.name; end
require 'psd/resources/layer_comps'
require 'psd/resources/slices'
require 'psd/resources/xmp_metadata'
require 'psd/resources/resolution_info'
48 changes: 48 additions & 0 deletions lib/psd/resources/resolution_info.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require 'psd/resources/base'

class PSD
class Resource
module Section
class ResolutionInfo < Base
RES_UNIT_NAMES = %w(pixel/inch pixel/cm).freeze
UNIT_NAMES = %w(in cm pt picas columns).freeze

resource_id 1005
name :resolution_info

attr_reader :h_res, :h_res_unit, :width_unit
attr_reader :v_res, :v_res_unit, :height_unit

def parse
# 32-bit fixed-point number (16.16)
@h_res = @file.read_uint.to_f / (1 << 16)
@h_res_unit = @file.read_ushort
@width_unit = @file.read_ushort

# 32-bit fixed-point number (16.16)
@v_res = @file.read_uint.to_f / (1 << 16)
@v_res_unit = @file.read_ushort
@height_unit = @file.read_ushort

@resource.data = self
end

def h_res_unit_name
RES_UNIT_NAMES.fetch(h_res_unit - 1, 'unknown')
end

def v_res_unit_name
RES_UNIT_NAMES.fetch(v_res_unit - 1, 'unknown')
end

def width_unit_name
UNIT_NAMES.fetch(width_unit - 1, 'unknown')
end

def height_unit_name
UNIT_NAMES.fetch(height_unit - 1, 'unknown')
end
end
end
end
end

0 comments on commit 31c7ddd

Please sign in to comment.