Class: ImageSize
- Inherits:
-
Object
- Object
- ImageSize
- Defined in:
- lib/image_size.rb
Defined Under Namespace
Classes: ImageReader, Size
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Image format.
-
#height ⇒ Object
(also: #h)
readonly
Image height.
-
#width ⇒ Object
(also: #w)
readonly
Image width.
Class Method Summary collapse
-
.path(path) ⇒ Object
Given path to image finds its format, width and height.
Instance Method Summary collapse
-
#initialize(data) ⇒ ImageSize
constructor
Given image as IO, StringIO, Tempfile or String finds its format and dimensions.
- #size ⇒ Object
Constructor Details
#initialize(data) ⇒ ImageSize
Given image as IO, StringIO, Tempfile or String finds its format and dimensions
48 49 50 51 52 53 54 |
# File 'lib/image_size.rb', line 48 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
#format ⇒ Object (readonly)
Image format
57 58 59 |
# File 'lib/image_size.rb', line 57 def format @format end |
#height ⇒ Object (readonly) Also known as: h
Image height
64 65 66 |
# File 'lib/image_size.rb', line 64 def height @height end |
#width ⇒ Object (readonly) Also known as: w
Image width
60 61 62 |
# File 'lib/image_size.rb', line 60 def width @width end |
Class Method Details
.path(path) ⇒ Object
Given path to image finds its format, width and height
43 44 45 |
# File 'lib/image_size.rb', line 43 def self.path(path) open(path, 'rb'){ |f| new(f) } end |