class Natour::Image

Attributes

date_time[R]
path[R]

Public Class Methods

load_file(filename) click to toggle source
# File lib/natour/image.rb, line 24
def self.load_file(filename)
  Image.new(filename, Vips::Image.new_from_file(filename))
end
new(path, image) click to toggle source
# File lib/natour/image.rb, line 11
def initialize(path, image)
  @path = path
  @image = image
  orientation = get_field('exif-ifd0-Orientation')
  @landscape = if orientation
                 orientation[/^(\d) \(/, 1].to_i.between?(1, 4)
               else
                 image.width >= image.height
               end
  date_time = get_field('exif-ifd0-DateTime')
  @date_time = Timeliness.parse(date_time[/^(.*?) \(/, 1], format: 'yyyy:mm:dd hh:nn:ss') if date_time
end

Public Instance Methods

autorotate() click to toggle source
# File lib/natour/image.rb, line 32
def autorotate
  Image.new(@path, @image.autorot)
end
landscape?() click to toggle source
# File lib/natour/image.rb, line 28
def landscape?
  @landscape
end
save_as(filename) click to toggle source
# File lib/natour/image.rb, line 46
def save_as(filename)
  FileUtils.mkdir_p(Pathname(filename).dirname)
  StdoutUtils.suppress_output { @image.write_to_file(filename) }
end
shrink_to(maxdim) click to toggle source
# File lib/natour/image.rb, line 36
def shrink_to(maxdim)
  scale = maxdim / @image.size.max.to_f
  image = if scale < 1.0
            @image.resize(scale)
          else
            @image.copy
          end
  Image.new(@path, image)
end

Private Instance Methods

get_field(name) click to toggle source
# File lib/natour/image.rb, line 53
def get_field(name)
  @image.get(name) if @image.get_fields.include?(name)
end