Class: ImageSize
- Inherits:
-
Object
- Object
- ImageSize
- Defined in:
- lib/image_size.rb,
lib/image_size/reader.rb,
lib/image_size/uri_reader.rb,
lib/image_size/chunky_reader.rb,
lib/image_size/string_reader.rb,
lib/image_size/stream_io_reader.rb,
lib/image_size/seekable_io_reader.rb
Overview
Experimental, not yet part of stable API
It adds ability to fetch image meta from HTTP server while downloading only needed chunks if the server recognises Range header, otherwise fetches only required amount of data
Defined Under Namespace
Modules: ChunkyReader, Reader, URIReader Classes: FormatError, SeekableIOReader, Size, StreamIOReader, StringReader
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.
- .url(url) ⇒ Object
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
49 50 51 52 53 54 |
# File 'lib/image_size.rb', line 49 def initialize(data) Reader.open(data) do |ir| @format = detect_format(ir) @width, @height = send("size_of_#{@format}", ir) if @format end 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
.dpi ⇒ Object
Used for svg
39 40 41 |
# File 'lib/image_size.rb', line 39 def self.dpi @dpi || 72 end |
.dpi=(dpi) ⇒ Object
Used for svg
44 45 46 |
# File 'lib/image_size.rb', line 44 def self.dpi=(dpi) @dpi = dpi.to_f end |
.path(path) ⇒ Object
Given path to image finds its format, width and height
34 35 36 |
# File 'lib/image_size.rb', line 34 def self.path(path) new(Pathname.new(path)) end |
.url(url) ⇒ Object
123 124 125 |
# File 'lib/image_size/uri_reader.rb', line 123 def self.url(url) new(url.is_a?(URI) ? url : URI(url)) end |