lib/psd.rb in psd-1.4.3 vs lib/psd.rb in psd-1.4.4
- old
+ new
@@ -22,15 +22,10 @@
class PSD
include Logger
include Helpers
include NodeExporting
- DEFAULTS = {
- parse_image: false,
- parse_layer_images: false
- }
-
attr_reader :file, :opts
alias :options :opts
# Opens the named file, parses it, and makes it available for reading. Then, closes it after you're finished.
# @param filename [String] the name of the file to open
@@ -53,11 +48,11 @@
# Create and store a reference to our PSD file
def initialize(file, opts={})
@file = PSD::File.new(file, 'rb')
@file.seek 0 # If the file was previously used and not closed
- @opts = DEFAULTS.merge(opts)
+ @opts = opts
@header = nil
@resources = nil
@layer_mask = nil
@parsed = false
end
@@ -72,11 +67,11 @@
# parse all sections of the PSD.
def parse!
header
resources
layer_mask
- image if @opts[:parse_image]
+ image
@parsed = true
return true
end
@@ -119,10 +114,15 @@
def image
ensure_header
ensure_resources
ensure_layer_mask
- @image ||= Image.new(@file, @header).parse
+ @image ||= (
+ # The image is the last section in the file, so we don't have to
+ # bother with skipping over the bytes to read more data.
+ image = Image.new(@file, @header)
+ LazyExecute.new(image, @file).later(:parse)
+ )
end
# Export the current file to a new PSD. This may or may not work.
def export(file)
parse! unless parsed?
\ No newline at end of file