Module: PSD::Helpers

Included in:
PSD
Defined in:
lib/psd/helpers.rb

Overview

Various helper methods that make accessing PSD data easier since it’s split up among various sections.

Instance Method Summary collapse

Instance Method Details

#actual_layersObject

All of the layers, but filters out the section dividers.



21
22
23
# File 'lib/psd/helpers.rb', line 21

def actual_layers
  layers.delete_if { |l| l.folder? || l.folder_end? }
end

#foldersObject

All of the folders in the document.



26
27
28
# File 'lib/psd/helpers.rb', line 26

def folders
  layers.select { |l| l.folder? }
end

#guidesObject



43
44
45
# File 'lib/psd/helpers.rb', line 43

def guides
  resource(:guides).to_a
end

#heightObject

Height of the entire PSD document, in pixels.



11
12
13
# File 'lib/psd/helpers.rb', line 11

def height
  header.rows
end

#layer_compsObject



39
40
41
# File 'lib/psd/helpers.rb', line 39

def layer_comps
  resource(:layer_comps).to_a
end

#layersObject

All of the layers in this document, including section divider layers.



16
17
18
# File 'lib/psd/helpers.rb', line 16

def layers
  layer_mask.layers
end

#resource(id) ⇒ Object



35
36
37
# File 'lib/psd/helpers.rb', line 35

def resource(id)
  @resources[id].nil? ? nil : @resources[id].data
end

#slicesObject



47
48
49
# File 'lib/psd/helpers.rb', line 47

def slices
  @slices ||= resource(:slices).to_a.map { |s| Slice.new(self, s) }
end

#treeObject

Constructs a tree of the current document for easy traversal and data access.



31
32
33
# File 'lib/psd/helpers.rb', line 31

def tree
  @root ||= PSD::Node::Root.new(self)
end

#widthObject

Width of the entire PSD document, in pixels.



6
7
8
# File 'lib/psd/helpers.rb', line 6

def width
  header.cols
end