Class: ImageSize
- Inherits:
-
Object
- Object
- ImageSize
- Defined in:
- lib/image_size.rb
Overview
Determine image format and size
Defined Under Namespace
Classes: FormatError, 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
-
.dpi ⇒ Object
Used for svg.
-
.dpi=(dpi) ⇒ Object
Used for svg.
-
.path(path) ⇒ Object
Given path to image finds its format, width and height.
Instance Method Summary collapse
-
#initialize(data) ⇒ ImageSize
constructor
Given image as any class responding to read and eof? or data as String, finds its format and dimensions.
- #size ⇒ Object
Constructor Details
#initialize(data) ⇒ ImageSize
Given image as any class responding to read and eof? or data as String, finds its format and dimensions
60 61 62 63 64 65 66 |
# File 'lib/image_size.rb', line 60 def initialize(data) ir = ImageReader.new(data) @format = detect_format(ir) return unless @format @width, @height = send("size_of_#{@format}", ir) end |
Instance Attribute Details
#format ⇒ Object (readonly)
Image format
69 70 71 |
# File 'lib/image_size.rb', line 69 def format @format end |
#height ⇒ Object (readonly) Also known as: h
Image height
76 77 78 |
# File 'lib/image_size.rb', line 76 def height @height end |
#width ⇒ Object (readonly) Also known as: w
Image width
72 73 74 |
# File 'lib/image_size.rb', line 72 def width @width end |
Class Method Details
.dpi ⇒ Object
Used for svg
50 51 52 |
# File 'lib/image_size.rb', line 50 def self.dpi @dpi || 72 end |
.dpi=(dpi) ⇒ Object
Used for svg
55 56 57 |
# File 'lib/image_size.rb', line 55 def self.dpi=(dpi) @dpi = dpi.to_f end |
.path(path) ⇒ Object
Given path to image finds its format, width and height
45 46 47 |
# File 'lib/image_size.rb', line 45 def self.path(path) File.open(path, 'rb'){ |f| new(f) } end |