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_layers ⇒ Object

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

#folders ⇒ Object

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

#guides ⇒ Object



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

def guides
  resource(:guides).to_a
end

#height ⇒ Object

Height of the entire PSD document, in pixels.



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

def height
  header.rows
end

#layer_comps ⇒ Object



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

def layer_comps
  resource(:layer_comps).to_a
end

#layers ⇒ Object

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

#slices ⇒ Object



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

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

#tree ⇒ Object

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

#width ⇒ Object

Width of the entire PSD document, in pixels.



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

def width
  header.cols
end