class ImageSet

Attributes

orig[R]
thumbl[R]
thumbs[R]

Public Class Methods

new(path, fullpath, realpath) click to toggle source

TODO abort on invalid filesize

# File lib/zarchitect/image_set.rb, line 5
def initialize(path, fullpath, realpath)
  @thumbl = nil
  @thumbs = nil
  # path = /section/title/img.png
  # fullpath = _files/section/title/img.png
  # realpath = _html/files/section/title/img.png
  filename  = File.basename(path, ".*")
  extension = File.extname(path)
  realdir   = File.dirname(realpath)
  @orig = Image.new(fullpath, false)

  # check if thumbnails exist
  # attempt to create them if not
  thumbs_path = "#{File.join(realdir, filename)}-thumbs#{extension}"
  thumbl_path = "#{File.join(realdir, filename)}-thumbl#{extension}"
  @orig.thumbs_f = File.exist?(thumbs_path)
  @orig.thumbl_f = File.exist?(thumbl_path)
  unless @orig.thumb_small?
    if @orig.larger_than_thumb_small?
      r = @orig.create_thumbnail(thumbs_path, Zarchitect.conf.thumbs[0].to_i,
                                 Zarchitect.conf.thumbs[1].to_i)
      @orig.thumbs_f = r
    end
  end
  unless @orig.thumb_large?
    if @orig.larger_than_thumb_small?
      r = @orig.create_thumbnail(thumbl_path, Zarchitect.conf.thumbl[0].to_i,
                                 Zarchitect.conf.thumbl[1].to_i)
      @orig.thumbl_f = r
    end
  end
  # set thumbnails if created
  if @orig.thumb_small?
    @thumbs = Image.new(thumbs_path, true)
  end
  if @orig.thumb_large?
    @thumbl = Image.new(thumbl_path, true)
  end

end