Class: ImageSize

Inherits:
Object
  • Object
show all
Defined in:
lib/image_size.rb

Defined Under Namespace

Classes: ImageReader, Size

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ImageSize

Given image as IO, StringIO, Tempfile or String finds its format and dimensions



53
54
55
56
57
58
59
# File 'lib/image_size.rb', line 53

def initialize(data)
  ir = ImageReader.new(data)
  if @format = detect_format(ir)
    @width, @height = self.send("size_of_#{@format}", ir)
  end
  ir.rewind
end

Instance Attribute Details

#formatObject (readonly)

Image format



62
63
64
# File 'lib/image_size.rb', line 62

def format
  @format
end

#heightObject (readonly) Also known as: h

Image height



69
70
71
# File 'lib/image_size.rb', line 69

def height
  @height
end

#widthObject (readonly) Also known as: w

Image width



65
66
67
# File 'lib/image_size.rb', line 65

def width
  @width
end

Class Method Details

.path(path) ⇒ Object

Given path to image finds its format, width and height



48
49
50
# File 'lib/image_size.rb', line 48

def self.path(path)
  open(path, 'rb'){ |f| new(f) }
end

Instance Method Details

#sizeObject

get image width and height as an array which to_s method returns “##widthx##height



73
74
75
76
77
# File 'lib/image_size.rb', line 73

def size
  if format
    Size.new([width, height])
  end
end