Sha256: 81bd5b72ceb3651ce963909186cb3c0c62e6a51cc7074b177bd43af44fdb4c4e

Contents?: true

Size: 757 Bytes

Versions: 1

Compression:

Stored size: 757 Bytes

Contents

require 'vips'
require 'timeliness'

module Natour
  class Image
    attr_reader :path
    attr_reader :date_time

    def initialize(path)
      @path = path
      image = Vips::Image.new_from_file(path)
      width, height = image.size
      @portrait = width < height
      orientation = image.get('exif-ifd0-Orientation')
      @portrait = orientation[/^(\d) \(/, 1].to_i.between?(5, 8)
      date_time = image.get('exif-ifd0-DateTime')
      @date_time = Timeliness.parse(
        date_time[/^(.*?) \(/, 1],
        format: 'yyyy:mm:dd hh:nn:ss'
      )
    rescue Vips::Error => e
      raise unless e.to_s =~ /exif-ifd0-(Orientation|DateTime)/
    end

    def portrait?
      @portrait
    end

    def landscape?
      !portrait?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
natour-0.1.0 lib/natour/image.rb