Compare commits
251 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
a992939223 | ||
|
cce874f025 | ||
|
4c06b15fa8 | ||
|
7f6a50c6a4 | ||
|
ba61a28d14 | ||
|
729438e55b | ||
|
d69288b504 | ||
|
b6720dfdf7 | ||
|
499865e47a | ||
|
cad7175e06 | ||
|
a891d8f43a | ||
|
2c8539d503 | ||
|
e7d8111784 | ||
|
ae60942b73 | ||
|
a5e4052dd5 | ||
|
b50c834fad | ||
|
054f563321 | ||
|
df84ad4c8d | ||
|
8d02ae8257 | ||
|
d1b1936b1d | ||
|
8495352ffe | ||
|
36ac12790d | ||
|
7de7faf8a3 | ||
|
7d86b403b0 | ||
|
99ac7d6df1 | ||
|
c5f76d0de2 | ||
|
f832581881 | ||
|
c763b215cf | ||
|
8994844702 | ||
|
b730e6b470 | ||
|
413bd34c00 | ||
|
6266b26b87 | ||
|
02d70df8c1 | ||
|
1fcc6c89ea | ||
|
71469cb64f | ||
|
edf9558114 | ||
|
c69d230098 | ||
|
d515546a1d | ||
|
23989af8f9 | ||
|
1a249b9e6d | ||
|
22bdc7ba06 | ||
|
2d546f4520 | ||
|
7c49d67439 | ||
|
fb319cda6e | ||
|
3fdd1767f5 | ||
|
7056a4b6c9 | ||
|
81b5b7d3df | ||
|
419bafca36 | ||
|
cb336762af | ||
|
5528ef98d4 | ||
|
b65d75c8a3 | ||
|
e5266ff249 | ||
|
f8d0b37e95 | ||
|
c295d5da98 | ||
|
6478cd33ac | ||
|
abd8059bd9 | ||
|
1a3e525c1d | ||
|
a1131d15bb | ||
|
f6559105f1 | ||
|
6025bd8819 | ||
|
4bdc514249 | ||
|
f0ea7da025 | ||
|
5dd8301141 | ||
|
31ea417d8e | ||
|
50b1631ae9 | ||
|
cd3ee0a624 | ||
|
f2efc8c6c9 | ||
|
9baee6d1b3 | ||
|
58dcc3072f | ||
|
9a1400ebcc | ||
|
e72139ae17 | ||
|
fcf871e637 | ||
|
a440798854 | ||
|
e8ad2254e8 | ||
|
98dcf9e491 | ||
|
fd3b5f2c4c | ||
|
ddf9f25cef | ||
|
437318220b | ||
|
e4c35d951e | ||
|
c78578c097 | ||
|
c183bb833d | ||
|
cb3a8cbeeb | ||
|
fcf1704595 | ||
|
c93903eb5c | ||
|
f1628c1539 | ||
|
e4c198a02c | ||
|
c57b07dc85 | ||
|
0d4dd4a7ed | ||
|
172b674a40 | ||
|
099c5e4233 | ||
|
45521bfd3e | ||
|
8386e11db4 | ||
|
b58af86658 | ||
|
967737b844 | ||
|
df31108b00 | ||
|
41088a55b6 | ||
|
2decef3e02 | ||
|
12a7dc4268 | ||
|
2e0436c58f | ||
|
bad902712c | ||
|
0d7ef4a548 | ||
|
021e5d3eb3 | ||
|
692a1058a0 | ||
|
d1e49be9fc | ||
|
6c7cdcd475 | ||
|
f82c2b192e | ||
|
a86e02db9c | ||
|
6f548c5509 | ||
|
18831de7de | ||
|
ddfb29998a | ||
|
0dcffe126e | ||
|
2132a8f99d | ||
|
3c5971e5b4 | ||
|
9cc77e6e4c | ||
|
2187189d72 | ||
|
11ca295071 | ||
|
929b4b76c5 | ||
|
d75d16e3c4 | ||
|
aa097226e8 | ||
|
15bc4111c4 | ||
|
c4ffaf827c | ||
|
a6222c47a5 | ||
|
283911c168 | ||
|
15f3e95b25 | ||
|
abccdd1365 | ||
|
c7cad12fa0 | ||
|
7bc37c590a | ||
|
2da45b1ed9 | ||
|
1be9e5cd7a | ||
|
0d4fbcbf76 | ||
|
32b5ba5c4b | ||
|
0cef2a777c | ||
|
35d365565f | ||
|
271fb5d646 | ||
|
2b4b69d80e | ||
|
921ed9a580 | ||
|
e46c41a507 | ||
|
7c10a0d8f9 | ||
|
ec1632b8ef | ||
|
3ca1029b0f | ||
|
6d489e6f6a | ||
|
bb4e64a455 | ||
|
5362469484 | ||
|
7c9ef44362 | ||
|
0adc60812c | ||
|
406c2a5734 | ||
|
bd150b54af | ||
|
ab07d1fe21 | ||
|
c89f556204 | ||
|
955d77a7e9 | ||
|
f92c8afffd | ||
|
bc43e8b570 | ||
|
b8e0bd7afb | ||
|
2daadda6fc | ||
|
31042836d4 | ||
|
88e2098d65 | ||
|
dde7d6c533 | ||
|
cbc17cbf69 | ||
|
e8aec702fa | ||
|
63924a2a00 | ||
|
a0808275f8 | ||
|
b9453d7733 | ||
|
13b0244968 | ||
|
c99b127d1b | ||
|
87cc1e7bdb | ||
|
2453c60d6e | ||
|
49bf0c0625 | ||
|
c5cf98f54e | ||
|
64b624c538 | ||
|
67d2368176 | ||
|
cc28a5b248 | ||
|
e54e1e0b23 | ||
|
e53d427455 | ||
|
a8826239e8 | ||
|
9ab057cb7a | ||
|
04d1030756 | ||
|
9c7ada1a41 | ||
|
fb051f6b2f | ||
|
094a94d581 | ||
|
670fd3f2e3 | ||
|
717c15d776 | ||
|
5320815974 | ||
|
f3ee9eeace | ||
|
d3982fa009 | ||
|
ca29078b07 | ||
|
4c1905fd66 | ||
|
f77a2b80bb | ||
|
5c64fc9d11 | ||
|
4a83842950 | ||
|
3c0c290ac8 | ||
|
05457f9e89 | ||
|
4c83a818a5 | ||
|
b550bd5615 | ||
|
ad567ff0da | ||
|
b7bc775f4f | ||
|
308e20cf45 | ||
|
e4a5412d87 | ||
|
013cd81ddb | ||
|
f27a0e5943 | ||
|
fe5b4d7f04 | ||
|
035ebe3ed6 | ||
|
39d9dfbf05 | ||
|
605bdc9452 | ||
|
88355932a9 | ||
|
3b84f548b1 | ||
|
36464d3bbc | ||
|
1511585281 | ||
|
4c20f466bb | ||
|
034f5446df | ||
|
5ebae8ea3b | ||
|
01af8e520e | ||
|
7547404945 | ||
|
8f9a740367 | ||
|
1c1eb99395 | ||
|
a63c1d34d4 | ||
|
617449d4b5 | ||
|
eb2ee31cd2 | ||
|
d05ea84b5d | ||
|
82d3525f40 | ||
|
ea0c36abea | ||
|
433c891313 | ||
|
e4f700e539 | ||
|
e534d26352 | ||
|
cae893b322 | ||
|
cef7cae610 | ||
|
2d989507f3 | ||
|
b018f1789f | ||
|
9c89f0f3fe | ||
|
2b531a801c | ||
|
45254569c9 | ||
|
d02670ef3f | ||
|
492b5c2840 | ||
|
9e5d4ea6a7 | ||
|
9e0258548a | ||
|
18d0908eeb | ||
|
b7aa051e8f | ||
|
8c2258a747 | ||
|
dfe73a1749 | ||
|
e68a9d155b | ||
|
e543e818fb | ||
|
bb0b1bb77f | ||
|
70ed89ee51 | ||
|
79160a9963 | ||
|
9aec213abb | ||
|
01c0b76457 | ||
|
327a3b55cd | ||
|
5aaa16fb4b | ||
|
014db79975 | ||
|
e863cfe1ba | ||
|
ed35f42592 | ||
|
d0e3338913 |
45
.github/workflows/test.yml
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
---
|
||||
name: Tests
|
||||
on: [ push, pull_request ]
|
||||
jobs:
|
||||
test:
|
||||
name: Test (Ruby ${{ matrix.ruby }})
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
ruby:
|
||||
- '2.3'
|
||||
- '2.4'
|
||||
- '2.5'
|
||||
- '2.6'
|
||||
- '2.7'
|
||||
- '3.0'
|
||||
- '3.1'
|
||||
- '3.2'
|
||||
- '3.3'
|
||||
- '3.4'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: ${{ matrix.ruby }}
|
||||
bundler-cache: true
|
||||
- run: bundle exec rake
|
||||
test_old_ruby:
|
||||
name: Test (Ruby ${{ matrix.ruby }})
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
ruby:
|
||||
- '2.0'
|
||||
- '2.1'
|
||||
- '2.2'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: ${{ matrix.ruby }}
|
||||
bundler-cache: true
|
||||
- run: bundle exec rake
|
2
.gitignore
vendored
@ -1 +1,3 @@
|
||||
pkg/
|
||||
Gemfile.lock
|
||||
.DS_Store
|
||||
|
@ -1,8 +0,0 @@
|
||||
language: ruby
|
||||
rvm:
|
||||
- 1.8.7
|
||||
- 1.9.2
|
||||
- 1.9.3
|
||||
- 2.0.0
|
||||
# uncomment this line if your project needs to run something other than `rake`:
|
||||
# script: bundle exec rspec spec
|
48
CHANGELOG
Normal file
@ -0,0 +1,48 @@
|
||||
Version 2.4.0
|
||||
|
||||
03-Jan-2025
|
||||
|
||||
- IMPROVED: Refactor code into multiple files
|
||||
- FIX: error rising from redirects to unknown url scheme
|
||||
- FIX: Handle tiff format with long dimensions values
|
||||
- FIX: Remove problematic dependency on base64 gem
|
||||
- IMPROVED: properties including content_length are fetched more lazily improving performance
|
||||
|
||||
Version 2.3.1
|
||||
|
||||
01-Apr-2024
|
||||
|
||||
- FIX: avoid bug where a NoMethodError exception is raised on faulty images
|
||||
|
||||
Version 2.3.0
|
||||
|
||||
24-Dec-2023
|
||||
|
||||
- FIX: replace test tiff that triggers Clam-AV
|
||||
- FIX: certain heif files could not be parsed
|
||||
- FEATURE: Adds animated support for png
|
||||
|
||||
Version 2.2.7
|
||||
|
||||
23-May-2023
|
||||
|
||||
- FEATURE: Adds animated? support for webp and avif images
|
||||
|
||||
Version 2.2.6
|
||||
|
||||
16-December-2021
|
||||
|
||||
- FEATURE: Add support for AVIF support
|
||||
|
||||
Version 2.2.5
|
||||
|
||||
10-August-2021
|
||||
|
||||
- FIX: handle HEIC/HEIF rotation angle
|
||||
|
||||
Version 2.2.4
|
||||
|
||||
02-June-2021
|
||||
|
||||
- FEATURE: Added support for HEIC format
|
||||
- FIX: Support SVG files that start with a BOM character
|
22
Gemfile.lock
@ -1,22 +0,0 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
fastimage (1.5.5)
|
||||
addressable (~> 2.3, >= 2.3.5)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
addressable (2.3.5)
|
||||
fakeweb (1.3.0)
|
||||
rake (10.1.0)
|
||||
rdoc (4.0.0)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
fakeweb (~> 1.3)
|
||||
fastimage!
|
||||
rake
|
||||
rdoc
|
205
README.md
Normal file
@ -0,0 +1,205 @@
|
||||
[](https://rubygems.org/gems/fastimage)
|
||||
[](https://github.com/sdsykes/fastimage/actions/workflows/test.yml)
|
||||
|
||||
# FastImage
|
||||
|
||||
**FastImage finds the size or type of an image given its uri by fetching as little as needed**
|
||||
|
||||
## The problem
|
||||
|
||||
Your app needs to find the size or type of an image. This could be for adding width and height attributes to an image tag, for adjusting layouts or overlays to fit an image or any other of dozens of reasons.
|
||||
|
||||
But the image is not locally stored - it's on another asset server, or in the cloud - at Amazon S3 for example.
|
||||
|
||||
You don't want to download the entire image to your app server - it could be many tens of kilobytes, or even megabytes just to get this information. For most common image types (GIF, PNG, BMP etc.), the size of the image is simply stored at the start of the file. For JPEG files it's a little bit more complex, but even so you do not need to fetch much of the image to find the size.
|
||||
|
||||
FastImage does this minimal fetch for image types GIF, JPEG, PNG, TIFF, BMP, ICO, CUR, PSD, SVG, WEBP and JXL. And it doesn't rely on installing external libraries such as RMagick (which relies on ImageMagick or GraphicsMagick) or ImageScience (which relies on FreeImage).
|
||||
|
||||
You only need supply the uri, and FastImage will do the rest.
|
||||
|
||||
## Features
|
||||
|
||||
- Reads local (and other) files - anything that is not parseable as a URI will be interpreted as a filename, and - will attempt to open it with `File#open`.
|
||||
|
||||
- Automatically reads from any object that responds to `:read` - for instance an IO object if that is passed instead of a URI.
|
||||
|
||||
- Follows up to 4 HTTP redirects to get the image.
|
||||
|
||||
- Obey the `http_proxy` setting in your environment to route requests via a proxy. You can also pass a `:proxy` argument if you want to specify the proxy address in the call.
|
||||
|
||||
- Add a timeout to the request which will limit the request time by passing `:timeout => number_of_seconds`.
|
||||
|
||||
- Returns `nil` if it encounters an error, but you can pass `:raise_on_failure => true` to get an exception.
|
||||
|
||||
- Provides a reader for the content length header provided in HTTP. This may be useful to assess the file size of an image, but do not rely on it exclusively - it will not be present in chunked responses for instance.
|
||||
|
||||
- Accepts additional HTTP headers. This can be used to set a user agent or referrer which some servers require. Pass an `:http_header` argument to specify headers, e.g., `:http_header => {'User-Agent' => 'Fake Browser'}`.
|
||||
|
||||
- Gives you information about the parsed display orientation of an image with Exif data (jpeg or tiff).
|
||||
|
||||
- Handles [Data URIs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs) correctly.
|
||||
|
||||
## Security
|
||||
|
||||
Take care to sanitise the strings passed to FastImage; it will try to read from whatever is passed.
|
||||
|
||||
## Examples
|
||||
|
||||
```ruby
|
||||
require 'fastimage'
|
||||
|
||||
FastImage.size("https://switchstep.com/images/ios.gif")
|
||||
=> [196, 283] # width, height
|
||||
FastImage.type("http://switchstep.com/images/ss_logo.png")
|
||||
=> :png
|
||||
FastImage.type("/some/local/file.gif")
|
||||
=> :gif
|
||||
File.open("/some/local/file.gif", "r") {|io| FastImage.type(io)}
|
||||
=> :gif
|
||||
FastImage.size("http://switchstep.com/images/favicon.ico", :raise_on_failure=>true, :timeout=>0.01)
|
||||
=> raises FastImage::ImageFetchFailure
|
||||
FastImage.size("http://switchstep.com/images/favicon.ico", :raise_on_failure=>true, :timeout=>2)
|
||||
=> [16, 16]
|
||||
FastImage.size("http://switchstep.com/images/faulty.jpg", :raise_on_failure=>true)
|
||||
=> raises FastImage::SizeNotFound
|
||||
FastImage.new("http://switchstep.com/images/ss_logo.png").content_length
|
||||
=> 4679
|
||||
FastImage.size("http://switchstep.com/images/ss_logo.png", :http_header => {'User-Agent' => 'Fake Browser'})
|
||||
=> [300, 300]
|
||||
FastImage.new("http://switchstep.com/images/ExifOrientation3.jpg").orientation
|
||||
=> 3
|
||||
FastImage.size("data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
|
||||
=> [1, 1]
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
### Gem
|
||||
|
||||
```sh
|
||||
gem install fastimage
|
||||
```
|
||||
|
||||
### Bundler
|
||||
|
||||
Add fastimage to your Gemfile.
|
||||
|
||||
```ruby
|
||||
gem 'fastimage'
|
||||
```
|
||||
|
||||
Then you're off - just use `FastImage.size()` and `FastImage.type()` in your code as in the examples.
|
||||
|
||||
## Documentation
|
||||
|
||||
http://sdsykes.github.io/fastimage/rdoc/FastImage.html
|
||||
|
||||
## Maintainer
|
||||
|
||||
FastImage is maintained by Stephen Sykes (sdsykes). SamSaffron also helps out from time to time (thanks!).
|
||||
|
||||
## Benchmark
|
||||
|
||||
It's way faster than conventional methods for most types of file when fetching over the wire. Compared here by using OpenURI which will fetch the whole file.
|
||||
|
||||
```ruby
|
||||
require 'benchmark'
|
||||
require 'fastimage'
|
||||
require 'open-uri'
|
||||
|
||||
uri = "http://upload.wikimedia.org/wikipedia/commons/b/b4/Mardin_1350660_1350692_33_images.jpg"
|
||||
puts Benchmark.measure {URI.open(uri, 'rb') {|fh| p FastImage.size(fh)}}
|
||||
[9545, 6623]
|
||||
0.059088 0.067694 0.126782 ( 0.808131)
|
||||
|
||||
puts Benchmark.measure {p FastImage.size(uri)}
|
||||
[9545, 6623]
|
||||
0.006198 0.001563 0.007761 ( 0.162021)
|
||||
```
|
||||
|
||||
The file is fetched in about 0.8 seconds in this test (the number in brackets is the total time taken), but as FastImage doesn't need to fetch the whole thing, it completes in 0.16s.
|
||||
|
||||
You'll see similar excellent results for the other file types.
|
||||
|
||||
```ruby
|
||||
require 'benchmark'
|
||||
require 'fastimage'
|
||||
require 'open-uri'
|
||||
|
||||
uri = "https://upload.wikimedia.org/wikipedia/commons/a/a9/Augustine_Herrman_1670_Map_Virginia_Maryland.tiff"
|
||||
puts Benchmark.measure {URI.open(uri, 'rb') {|fh| p FastImage.size(fh)}}
|
||||
[12805, 10204]
|
||||
1.332587 2.049915 3.382502 ( 19.925270)
|
||||
|
||||
puts Benchmark.measure {p FastImage.size(uri)}
|
||||
[12805, 10204]
|
||||
0.004593 0.000924 0.005517 ( 0.100592)
|
||||
```
|
||||
|
||||
Some tiff files however do not have their metadata near the start of the file.
|
||||
|
||||
```ruby
|
||||
require 'benchmark'
|
||||
require 'fastimage'
|
||||
require 'open-uri'
|
||||
|
||||
uri = "https://upload.wikimedia.org/wikipedia/commons/1/14/Center-Filled_LIMA.tif"
|
||||
puts Benchmark.measure {URI.open(uri, 'rb') {|fh| p FastImage.size(fh)}}
|
||||
[22841, 19404]
|
||||
0.350304 0.321104 0.671408 ( 3.053605)
|
||||
|
||||
puts Benchmark.measure {p FastImage.size(uri)}
|
||||
[22841, 19404]
|
||||
0.163443 0.214301 0.377744 ( 2.880414)
|
||||
```
|
||||
|
||||
Note that if you want a really fast result for this file type, [image_size](https://github.com/toy/image_size?tab=readme-ov-file#experimental-fetch-image-meta-from-http-server) might be useful as it has an optimisation for this (fetching only the needed data range).
|
||||
|
||||
```ruby
|
||||
require 'benchmark'
|
||||
require 'image_size/uri'
|
||||
require 'fastimage'
|
||||
|
||||
uri = "https://upload.wikimedia.org/wikipedia/commons/1/14/Center-Filled_LIMA.tif"
|
||||
puts Benchmark.measure {p ImageSize.url(uri).size }
|
||||
[22841, 19404]
|
||||
0.008983 0.001311 0.010294 ( 0.128986)
|
||||
|
||||
puts Benchmark.measure {p FastImage.size(uri)}
|
||||
[22841, 19404]
|
||||
0.163443 0.214301 0.377744 ( 2.880414)
|
||||
```
|
||||
|
||||
## Tests
|
||||
|
||||
You'll need to bundle, or `gem install fakeweb` and possibly also `gem install test-unit` to be able to run the tests.
|
||||
|
||||
```sh
|
||||
ruby test/test.rb
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
- [Pennysmalls - Find jpeg dimensions fast in pure Ruby, no image library needed](http://pennysmalls.wordpress.com/2008/08/19/find-jpeg-dimensions-fast-in-pure-ruby-no-ima/)
|
||||
- [Antti Kupila - Getting JPG dimensions with AS3 without loading the entire file](https://www.anttikupila.com/archive/getting-jpg-dimensions/)
|
||||
- [imagesize gem](https://rubygems.org/gems/imagesize)
|
||||
- [EXIF Reader](https://github.com/remvee/exifr)
|
||||
|
||||
## FastImage in other languages
|
||||
|
||||
- [Python by bmuller](https://github.com/bmuller/fastimage)
|
||||
- [Swift by kaishin](https://github.com/kaishin/ImageScout)
|
||||
- [Go by rubenfonseca](https://github.com/rubenfonseca/fastimage)
|
||||
- [PHP by tommoor](https://github.com/tommoor/fastimage)
|
||||
- [Node.js by ShogunPanda](https://github.com/ShogunPanda/fastimage)
|
||||
- [Objective C by kylehickinson](https://github.com/kylehickinson/FastImage)
|
||||
- [Android by qstumn](https://github.com/qstumn/FastImageSize)
|
||||
- [Flutter by ky1vstar](https://github.com/ky1vstar/fastimage.dart)
|
||||
|
||||
### Also of interest
|
||||
- [C++ by xiaozhuai](https://github.com/xiaozhuai/imageinfo)
|
||||
- [Rust by xiaozhuai](https://github.com/xiaozhuai/imageinfo-rs)
|
||||
|
||||
## Licence
|
||||
|
||||
MIT, see file "MIT-LICENSE"
|
130
README.textile
@ -1,130 +0,0 @@
|
||||
h1. FastImage
|
||||
|
||||
h4. FastImage finds the size or type of an image given its uri by fetching as little as needed
|
||||
|
||||
h2. The problem
|
||||
|
||||
Your app needs to find the size or type of an image. This could be for adding width and height attributes to an image tag, for adjusting layouts or overlays to fit an image or any other of dozens of reasons.
|
||||
|
||||
But the image is not locally stored - it's on another asset server, or in the cloud - at Amazon S3 for example.
|
||||
|
||||
You don't want to download the entire image to your app server - it could be many tens of kilobytes, or even megabytes just to get this information. For most common image types (GIF, PNG, BMP), the size of the image is simply stored at the start of the file. For JPEG files it's a little bit more complex, but even so you do not need to fetch much of the image to find the size.
|
||||
|
||||
FastImage does this minimal fetch for image types GIF, JPEG, PNG, TIFF, BMP and PSD. And it doesn't rely on installing external libraries such as RMagick (which relies on ImageMagick or GraphicsMagick) or ImageScience (which relies on FreeImage).
|
||||
|
||||
You only need supply the uri, and FastImage will do the rest.
|
||||
|
||||
h2. Features
|
||||
|
||||
Fastimage can also read local (and other) files, and uses the Addressable library to do so.
|
||||
|
||||
FastImage will automatically read from any object that responds to :read - for
|
||||
instance an IO object if that is passed instead of a URI.
|
||||
|
||||
FastImage will follow up to 4 HTTP redirects to get the image.
|
||||
|
||||
FastImage will obey the http_proxy setting in your environment to route requests via a proxy.
|
||||
|
||||
You can add a timeout to the request which will limit the request time by passing :timeout => number_of_seconds.
|
||||
|
||||
FastImage normally replies will nil if it encounters an error, but you can pass :raise_on_failure => true to get an exception.
|
||||
|
||||
h2. Examples
|
||||
|
||||
<pre lang="ruby"><code>
|
||||
require 'fastimage'
|
||||
|
||||
FastImage.size("http://stephensykes.com/images/ss.com_x.gif")
|
||||
=> [266, 56] # width, height
|
||||
FastImage.type("http://stephensykes.com/images/pngimage")
|
||||
=> :png
|
||||
FastImage.type("/some/local/file.gif")
|
||||
=> :gif
|
||||
FastImage.size("http://upload.wikimedia.org/wikipedia/commons/b/b4/Mardin_1350660_1350692_33_images.jpg", :raise_on_failure=>true, :timeout=>0.1)
|
||||
=> FastImage::ImageFetchFailure: FastImage::ImageFetchFailure
|
||||
FastImage.size("http://upload.wikimedia.org/wikipedia/commons/b/b4/Mardin_1350660_1350692_33_images.jpg", :raise_on_failure=>true, :timeout=>2.0)
|
||||
=> [9545, 6623]
|
||||
</code></pre>
|
||||
|
||||
h2. Installation
|
||||
|
||||
h4. Gem
|
||||
|
||||
bc. gem install fastimage
|
||||
|
||||
h4. Rails
|
||||
|
||||
Add fastimage to your Gemfile, and bundle.
|
||||
|
||||
Then you're off - just use @FastImage.size()@ and @FastImage.type()@ in your code as in the examples.
|
||||
|
||||
h2. Documentation
|
||||
|
||||
"http://sdsykes.github.io/fastimage/rdoc/FastImage.html":http://sdsykes.github.io/fastimage/rdoc/FastImage.html
|
||||
|
||||
h2. Benchmark
|
||||
|
||||
It's way faster than conventional methods (for example the image_size gem) for most types of file when fetching over the wire.
|
||||
|
||||
<pre lang="ruby"><code>
|
||||
irb> uri = "http://upload.wikimedia.org/wikipedia/commons/b/b4/Mardin_1350660_1350692_33_images.jpg"
|
||||
irb> puts Benchmark.measure {open(uri, 'rb') {|fh| p ImageSize.new(fh).size}}
|
||||
[9545, 6623]
|
||||
0.680000 0.250000 0.930000 ( 7.571887)
|
||||
|
||||
irb> puts Benchmark.measure {p FastImage.size(uri)}
|
||||
[9545, 6623]
|
||||
0.010000 0.000000 0.010000 ( 0.090640)
|
||||
</code></pre>
|
||||
|
||||
The file is fetched in about 7.5 seconds in this test (the number in brackets is the total time taken), but as FastImage doesn't need to fetch the whole thing, it completes in less than 0.1s.
|
||||
|
||||
You'll see similar excellent results for the other file types, except for TIFF. Unfortunately TIFFs tend to have their
|
||||
metadata towards the end of the file, so it makes little difference to do a minimal fetch. The result shown below is
|
||||
mostly dependent on the exact internet conditions during the test, and little to do with the library used.
|
||||
|
||||
<pre lang="ruby"><code>
|
||||
irb> uri = "http://upload.wikimedia.org/wikipedia/commons/1/11/Shinbutsureijoushuincho.tiff"
|
||||
irb> puts Benchmark.measure {open(uri, 'rb') {|fh| p ImageSize.new(fh).size}}
|
||||
[1120, 1559]
|
||||
1.080000 0.370000 1.450000 ( 13.766962)
|
||||
|
||||
irb> puts Benchmark.measure {p FastImage.size(uri)}
|
||||
[1120, 1559]
|
||||
3.490000 3.810000 7.300000 ( 11.754315)
|
||||
</code></pre>
|
||||
|
||||
h2. Tests
|
||||
|
||||
You'll need to @gem install fakeweb@ to be able to run the tests.
|
||||
|
||||
bc.. $ ruby test.rb
|
||||
Run options:
|
||||
|
||||
# Running tests:
|
||||
|
||||
Finished tests in 1.033640s, 23.2189 tests/s, 82.2337 assertions/s.
|
||||
24 tests, 85 assertions, 0 failures, 0 errors, 0 skips
|
||||
|
||||
h2. References
|
||||
|
||||
* "Pennysmalls - Find jpeg dimensions fast in pure Ruby, no image library needed":http://pennysmalls.wordpress.com/2008/08/19/find-jpeg-dimensions-fast-in-pure-ruby-no-ima/
|
||||
* "DZone - Determine Image Size":http://snippets.dzone.com/posts/show/805
|
||||
* "Antti Kupila - Getting JPG dimensions with AS3 without loading the entire file":http://www.anttikupila.com/flash/getting-jpg-dimensions-with-as3-without-loading-the-entire-file/
|
||||
* "imagesize gem documentation":http://imagesize.rubyforge.org/
|
||||
* "EXIF Reader":https://github.com/remvee/exifr
|
||||
|
||||
h2. Licence
|
||||
|
||||
MIT, see file "MIT-LICENSE":MIT-LICENSE
|
||||
|
||||
h2. Contributors
|
||||
|
||||
Pull requests and suggestions are always welcome. Thanks to all the contributors!
|
||||
|
||||
* @felixbuenemann
|
||||
* @speedmax
|
||||
* @sebastianludwig
|
||||
* @benjaminjackson
|
||||
* @muffinista
|
||||
* @marcandre
|
5
Rakefile
@ -1,5 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rdoc/task"
|
||||
require 'rake/testtask'
|
||||
require "rake/testtask"
|
||||
require "bundler/gem_tasks"
|
||||
|
||||
# Generate documentation
|
||||
Rake::RDocTask.new do |rd|
|
||||
|
@ -1,49 +1,30 @@
|
||||
require_relative "lib/fastimage/version"
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = %q{fastimage}
|
||||
s.version = "1.6.0"
|
||||
s.version = FastImage::VERSION
|
||||
|
||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||
s.required_ruby_version = '>= 1.9.2'
|
||||
s.authors = ["Stephen Sykes"]
|
||||
s.date = %q{2014-01-29}
|
||||
s.description = %q{FastImage finds the size or type of an image given its uri by fetching as little as needed.}
|
||||
s.email = %q{sdsykes@gmail.com}
|
||||
s.extra_rdoc_files = [
|
||||
"README.textile"
|
||||
"README.md"
|
||||
]
|
||||
s.files = [
|
||||
"MIT-LICENSE",
|
||||
"README.textile",
|
||||
"lib/fastimage.rb",
|
||||
"lib/fastimage/fbr.rb",
|
||||
"test/fixtures/faulty.jpg",
|
||||
"test/fixtures/test.bmp",
|
||||
"test/fixtures/test.gif",
|
||||
"test/fixtures/test.ico",
|
||||
"test/fixtures/test.jpg",
|
||||
"test/fixtures/test.png",
|
||||
"test/fixtures/test2.jpg",
|
||||
"test/fixtures/test3.jpg",
|
||||
"test/fixtures/test4.jpg",
|
||||
"test/fixtures/test.tiff",
|
||||
"test/fixtures/test2.tiff",
|
||||
"test/fixtures/exif_orientation.jpg",
|
||||
"test/fixtures/infinite.jpg",
|
||||
"test/fixtures/folder with spaces/test.bmp",
|
||||
"test/test.rb",
|
||||
"test/fixtures/test.psd"
|
||||
]
|
||||
"README.md"
|
||||
] + Dir.glob("lib/**/*")
|
||||
s.homepage = %q{http://github.com/sdsykes/fastimage}
|
||||
s.rdoc_options = ["--charset=UTF-8"]
|
||||
s.require_paths = ["lib"]
|
||||
s.rubygems_version = %q{1.3.6}
|
||||
s.summary = %q{FastImage - Image info fast}
|
||||
s.add_runtime_dependency 'addressable', '~> 2.3', '>= 2.3.5'
|
||||
s.add_development_dependency 'fakeweb', '~> 1.3'
|
||||
s.add_development_dependency(%q<rake>, [">= 0"])
|
||||
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
||||
s.add_development_dependency 'fakeweb-fi', '~> 1.3'
|
||||
# Note rake 11 drops support for ruby 1.9.2
|
||||
s.add_development_dependency('rake', ">= 10.5")
|
||||
s.add_development_dependency('rdoc')
|
||||
s.add_development_dependency('test-unit')
|
||||
|
||||
s.test_files = [
|
||||
"test/test.rb"
|
||||
]
|
||||
s.licenses = ['MIT']
|
||||
end
|
||||
|
505
lib/fastimage.rb
@ -1,3 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
# coding: ASCII-8BIT
|
||||
|
||||
# FastImage finds the size or type of an image given its uri.
|
||||
@ -8,10 +9,10 @@
|
||||
# No external libraries such as ImageMagick are used here, this is a very lightweight solution to
|
||||
# finding image information.
|
||||
#
|
||||
# FastImage knows about GIF, JPEG, BMP, TIFF, PNG and PSD files.
|
||||
# FastImage knows about GIF, JPEG, BMP, TIFF, ICO, CUR, PNG, HEIC/HEIF, AVIF, PSD, SVG, WEBP and JXL files.
|
||||
#
|
||||
# FastImage can also read files from the local filesystem by supplying the path instead of a uri.
|
||||
# In this case FastImage uses the Addressable library to read the file in chunks of 256 bytes until
|
||||
# In this case FastImage reads the file in chunks of 256 bytes until
|
||||
# it has enough. This is possibly a useful bandwidth-saving feature if the file is on a network
|
||||
# attached disk rather than truly local.
|
||||
#
|
||||
@ -20,495 +21,53 @@
|
||||
#
|
||||
# FastImage will follow up to 4 HTTP redirects to get the image.
|
||||
#
|
||||
# FastImage also provides a reader for the content length header provided in HTTP.
|
||||
# This may be useful to assess the file size of an image, but do not rely on it exclusively -
|
||||
# it will not be present in chunked responses for instance.
|
||||
#
|
||||
# FastImage accepts additional HTTP headers. This can be used to set a user agent
|
||||
# or referrer which some servers require. Pass an :http_header argument to specify headers,
|
||||
# e.g., :http_header => {'User-Agent' => 'Fake Browser'}.
|
||||
#
|
||||
# FastImage can give you information about the parsed display orientation of an image with Exif
|
||||
# data (jpeg or tiff).
|
||||
#
|
||||
# === Examples
|
||||
# require 'fastimage'
|
||||
#
|
||||
# FastImage.size("http://stephensykes.com/images/ss.com_x.gif")
|
||||
# => [266, 56]
|
||||
# FastImage.type("http://stephensykes.com/images/pngimage")
|
||||
# FastImage.size("https://switchstep.com/images/ios.gif")
|
||||
# => [196, 283]
|
||||
# FastImage.type("http://switchstep.com/images/ss_logo.png")
|
||||
# => :png
|
||||
# FastImage.type("/some/local/file.gif")
|
||||
# => :gif
|
||||
# File.open("/some/local/file.gif", "r") {|io| FastImage.type(io)}
|
||||
# => :gif
|
||||
# FastImage.new("http://switchstep.com/images/ss_logo.png").content_length
|
||||
# => 4679
|
||||
# FastImage.new("http://switchstep.com/images/ExifOrientation3.jpg").orientation
|
||||
# => 3
|
||||
#
|
||||
# === References
|
||||
# * http://snippets.dzone.com/posts/show/805
|
||||
# * http://www.anttikupila.com/flash/getting-jpg-dimensions-with-as3-without-loading-the-entire-file/
|
||||
# * http://pennysmalls.wordpress.com/2008/08/19/find-jpeg-dimensions-fast-in-pure-ruby-no-ima/
|
||||
# * http://imagesize.rubyforge.org/
|
||||
# * https://rubygems.org/gems/imagesize
|
||||
# * https://github.com/remvee/exifr
|
||||
#
|
||||
|
||||
require 'net/https'
|
||||
require 'addressable/uri'
|
||||
require 'fastimage/fbr.rb'
|
||||
require 'delegate'
|
||||
require 'pathname'
|
||||
require 'zlib'
|
||||
require 'uri'
|
||||
require 'stringio'
|
||||
|
||||
class FastImage
|
||||
attr_reader :size, :type
|
||||
require_relative 'fastimage/fastimage'
|
||||
require_relative 'fastimage/version'
|
||||
|
||||
attr_reader :bytes_read
|
||||
|
||||
class FastImageException < StandardError # :nodoc:
|
||||
end
|
||||
class MoreCharsNeeded < FastImageException # :nodoc:
|
||||
end
|
||||
class UnknownImageType < FastImageException # :nodoc:
|
||||
end
|
||||
class ImageFetchFailure < FastImageException # :nodoc:
|
||||
end
|
||||
class SizeNotFound < FastImageException # :nodoc:
|
||||
end
|
||||
class CannotParseImage < FastImageException # :nodoc:
|
||||
end
|
||||
|
||||
DefaultTimeout = 2
|
||||
|
||||
LocalFileChunkSize = 256
|
||||
|
||||
# Returns an array containing the width and height of the image.
|
||||
# It will return nil if the image could not be fetched, or if the image type was not recognised.
|
||||
#
|
||||
# By default there is a timeout of 2 seconds for opening and reading from a remote server.
|
||||
# This can be changed by passing a :timeout => number_of_seconds in the options.
|
||||
#
|
||||
# If you wish FastImage to raise if it cannot size the image for any reason, then pass
|
||||
# :raise_on_failure => true in the options.
|
||||
#
|
||||
# FastImage knows about GIF, JPEG, BMP, TIFF, PNG and PSD files.
|
||||
#
|
||||
# === Example
|
||||
#
|
||||
# require 'fastimage'
|
||||
#
|
||||
# FastImage.size("http://stephensykes.com/images/ss.com_x.gif")
|
||||
# => [266, 56]
|
||||
# FastImage.size("http://stephensykes.com/images/pngimage")
|
||||
# => [16, 16]
|
||||
# FastImage.size("http://farm4.static.flickr.com/3023/3047236863_9dce98b836.jpg")
|
||||
# => [500, 375]
|
||||
# FastImage.size("http://www-ece.rice.edu/~wakin/images/lena512.bmp")
|
||||
# => [512, 512]
|
||||
# FastImage.size("test/fixtures/test.jpg")
|
||||
# => [882, 470]
|
||||
# FastImage.size("http://pennysmalls.com/does_not_exist")
|
||||
# => nil
|
||||
# FastImage.size("http://pennysmalls.com/does_not_exist", :raise_on_failure=>true)
|
||||
# => raises FastImage::ImageFetchFailure
|
||||
# FastImage.size("http://stephensykes.com/favicon.ico", :raise_on_failure=>true)
|
||||
# => raises FastImage::UnknownImageType
|
||||
# FastImage.size("http://stephensykes.com/favicon.ico", :raise_on_failure=>true, :timeout=>0.01)
|
||||
# => raises FastImage::ImageFetchFailure
|
||||
# FastImage.size("http://stephensykes.com/images/faulty.jpg", :raise_on_failure=>true)
|
||||
# => raises FastImage::SizeNotFound
|
||||
#
|
||||
# === Supported options
|
||||
# [:timeout]
|
||||
# Overrides the default timeout of 2 seconds. Applies both to reading from and opening the http connection.
|
||||
# [:raise_on_failure]
|
||||
# If set to true causes an exception to be raised if the image size cannot be found for any reason.
|
||||
#
|
||||
def self.size(uri, options={})
|
||||
new(uri, options).size
|
||||
end
|
||||
|
||||
# Returns an symbol indicating the image type fetched from a uri.
|
||||
# It will return nil if the image could not be fetched, or if the image type was not recognised.
|
||||
#
|
||||
# By default there is a timeout of 2 seconds for opening and reading from a remote server.
|
||||
# This can be changed by passing a :timeout => number_of_seconds in the options.
|
||||
#
|
||||
# If you wish FastImage to raise if it cannot find the type of the image for any reason, then pass
|
||||
# :raise_on_failure => true in the options.
|
||||
#
|
||||
# === Example
|
||||
#
|
||||
# require 'fastimage'
|
||||
#
|
||||
# FastImage.type("http://stephensykes.com/images/ss.com_x.gif")
|
||||
# => :gif
|
||||
# FastImage.type("http://stephensykes.com/images/pngimage")
|
||||
# => :png
|
||||
# FastImage.type("http://farm4.static.flickr.com/3023/3047236863_9dce98b836.jpg")
|
||||
# => :jpeg
|
||||
# FastImage.type("http://www-ece.rice.edu/~wakin/images/lena512.bmp")
|
||||
# => :bmp
|
||||
# FastImage.type("test/fixtures/test.jpg")
|
||||
# => :jpeg
|
||||
# FastImage.type("http://pennysmalls.com/does_not_exist")
|
||||
# => nil
|
||||
# File.open("/some/local/file.gif", "r") {|io| FastImage.type(io)}
|
||||
# => :gif
|
||||
# FastImage.type("test/fixtures/test.tiff")
|
||||
# => :tiff
|
||||
# FastImage.type("test/fixtures/test.psd")
|
||||
# => :psd
|
||||
#
|
||||
# === Supported options
|
||||
# [:timeout]
|
||||
# Overrides the default timeout of 2 seconds. Applies both to reading from and opening the http connection.
|
||||
# [:raise_on_failure]
|
||||
# If set to true causes an exception to be raised if the image type cannot be found for any reason.
|
||||
#
|
||||
def self.type(uri, options={})
|
||||
new(uri, options.merge(:type_only=>true)).type
|
||||
end
|
||||
|
||||
def initialize(uri, options={})
|
||||
@property = options[:type_only] ? :type : :size
|
||||
@timeout = options[:timeout] || DefaultTimeout
|
||||
@uri = uri
|
||||
|
||||
if uri.respond_to?(:read)
|
||||
fetch_using_read(uri)
|
||||
else
|
||||
begin
|
||||
@parsed_uri = Addressable::URI.parse(uri)
|
||||
rescue Addressable::URI::InvalidURIError
|
||||
fetch_using_open_uri
|
||||
else
|
||||
if @parsed_uri.scheme == "http" || @parsed_uri.scheme == "https"
|
||||
fetch_using_http
|
||||
else
|
||||
fetch_using_open_uri
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
uri.rewind if uri.respond_to?(:rewind)
|
||||
|
||||
raise SizeNotFound if options[:raise_on_failure] && @property == :size && !@size
|
||||
|
||||
rescue Timeout::Error, SocketError, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET,
|
||||
ImageFetchFailure, Net::HTTPBadResponse, EOFError, Errno::ENOENT
|
||||
raise ImageFetchFailure if options[:raise_on_failure]
|
||||
rescue NoMethodError # 1.8.7p248 can raise this due to a net/http bug
|
||||
raise ImageFetchFailure if options[:raise_on_failure]
|
||||
rescue UnknownImageType
|
||||
raise UnknownImageType if options[:raise_on_failure]
|
||||
rescue CannotParseImage
|
||||
if options[:raise_on_failure]
|
||||
if @property == :size
|
||||
raise SizeNotFound
|
||||
else
|
||||
raise ImageFetchFailure
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fetch_using_http
|
||||
@redirect_count = 0
|
||||
|
||||
fetch_using_http_from_parsed_uri
|
||||
end
|
||||
|
||||
def fetch_using_http_from_parsed_uri
|
||||
setup_http
|
||||
@http.request_get(@parsed_uri.request_uri, 'Accept-Encoding' => 'identity') do |res|
|
||||
if res.is_a?(Net::HTTPRedirection) && @redirect_count < 4
|
||||
@redirect_count += 1
|
||||
begin
|
||||
newly_parsed_uri = Addressable::URI.parse(res['Location'])
|
||||
# The new location may be relative - check for that
|
||||
if newly_parsed_uri.scheme != "http" && newly_parsed_uri.scheme != "https"
|
||||
@parsed_uri.path = res['Location']
|
||||
else
|
||||
@parsed_uri = newly_parsed_uri
|
||||
end
|
||||
rescue Addressable::URI::InvalidURIError
|
||||
else
|
||||
fetch_using_http_from_parsed_uri
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
raise ImageFetchFailure unless res.is_a?(Net::HTTPSuccess)
|
||||
|
||||
read_fiber = Fiber.new do
|
||||
res.read_body do |str|
|
||||
Fiber.yield str
|
||||
end
|
||||
end
|
||||
|
||||
parse_packets FiberStream.new(read_fiber)
|
||||
|
||||
break # needed to actively quit out of the fetch
|
||||
end
|
||||
end
|
||||
|
||||
def proxy_uri
|
||||
begin
|
||||
proxy = ENV['http_proxy'] && ENV['http_proxy'] != "" ? Addressable::URI.parse(ENV['http_proxy']) : nil
|
||||
rescue Addressable::URI::InvalidURIError
|
||||
proxy = nil
|
||||
end
|
||||
proxy
|
||||
end
|
||||
|
||||
def setup_http
|
||||
proxy = proxy_uri
|
||||
|
||||
if proxy
|
||||
@http = Net::HTTP::Proxy(proxy.host, proxy.port).new(@parsed_uri.host, @parsed_uri.inferred_port)
|
||||
else
|
||||
@http = Net::HTTP.new(@parsed_uri.host, @parsed_uri.inferred_port)
|
||||
end
|
||||
@http.use_ssl = (@parsed_uri.scheme == "https")
|
||||
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||
@http.open_timeout = @timeout
|
||||
@http.read_timeout = @timeout
|
||||
end
|
||||
|
||||
def fetch_using_read(readable)
|
||||
read_fiber = Fiber.new do
|
||||
while str = readable.read(LocalFileChunkSize)
|
||||
Fiber.yield str
|
||||
end
|
||||
end
|
||||
|
||||
parse_packets FiberStream.new(read_fiber)
|
||||
end
|
||||
|
||||
def fetch_using_open_uri
|
||||
open(@uri) do |s|
|
||||
fetch_using_read(s)
|
||||
end
|
||||
end
|
||||
|
||||
def parse_packets(stream)
|
||||
@stream = stream
|
||||
|
||||
begin
|
||||
result = send("parse_#{@property}")
|
||||
if result
|
||||
instance_variable_set("@#{@property}", result)
|
||||
else
|
||||
raise CannotParseImage
|
||||
end
|
||||
rescue FiberError
|
||||
raise CannotParseImage
|
||||
end
|
||||
end
|
||||
|
||||
def parse_size
|
||||
@type = parse_type unless @type
|
||||
send("parse_size_for_#{@type}")
|
||||
end
|
||||
|
||||
module StreamUtil # :nodoc:
|
||||
def read_byte
|
||||
read(1).ord
|
||||
end
|
||||
|
||||
def read_int
|
||||
read(2).unpack('n')[0]
|
||||
end
|
||||
end
|
||||
|
||||
class FiberStream # :nodoc:
|
||||
include StreamUtil
|
||||
attr_reader :pos
|
||||
|
||||
def initialize(read_fiber)
|
||||
@read_fiber = read_fiber
|
||||
@pos = 0
|
||||
@strpos = 0
|
||||
@str = ''
|
||||
end
|
||||
|
||||
def peek(n)
|
||||
while @strpos + n - 1 >= @str.size
|
||||
unused_str = @str[@strpos..-1]
|
||||
new_string = @read_fiber.resume
|
||||
raise CannotParseImage if !new_string
|
||||
|
||||
# we are dealing with bytes here, so force the encoding
|
||||
new_string.force_encoding("ASCII-8BIT") if String.method_defined? :force_encoding
|
||||
|
||||
@str = unused_str + new_string
|
||||
@strpos = 0
|
||||
end
|
||||
|
||||
result = @str[@strpos..(@strpos + n - 1)]
|
||||
end
|
||||
|
||||
def read(n)
|
||||
result = peek(n)
|
||||
@strpos += n
|
||||
@pos += n
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
class IOStream < SimpleDelegator # :nodoc:
|
||||
include StreamUtil
|
||||
end
|
||||
|
||||
def parse_type
|
||||
case @stream.peek(2)
|
||||
when "BM"
|
||||
:bmp
|
||||
when "GI"
|
||||
:gif
|
||||
when 0xff.chr + 0xd8.chr
|
||||
:jpeg
|
||||
when 0x89.chr + "P"
|
||||
:png
|
||||
when "II", "MM"
|
||||
:tiff
|
||||
when '8B'
|
||||
:psd
|
||||
else
|
||||
raise UnknownImageType
|
||||
end
|
||||
end
|
||||
|
||||
def parse_size_for_gif
|
||||
@stream.read(11)[6..10].unpack('SS')
|
||||
end
|
||||
|
||||
def parse_size_for_png
|
||||
@stream.read(25)[16..24].unpack('NN')
|
||||
end
|
||||
|
||||
def parse_size_for_jpeg
|
||||
loop do
|
||||
@state = case @state
|
||||
when nil
|
||||
@stream.read(2)
|
||||
:started
|
||||
when :started
|
||||
@stream.read_byte == 0xFF ? :sof : :started
|
||||
when :sof
|
||||
case @stream.read_byte
|
||||
when 0xe1 # APP1
|
||||
skip_chars = @stream.read_int - 2
|
||||
data = @stream.read(skip_chars)
|
||||
io = StringIO.new(data)
|
||||
if io.read(4) == "Exif"
|
||||
io.read(2)
|
||||
@exif = Exif.new(IOStream.new(io)) rescue nil
|
||||
end
|
||||
:started
|
||||
when 0xe0..0xef
|
||||
:skipframe
|
||||
when 0xC0..0xC3, 0xC5..0xC7, 0xC9..0xCB, 0xCD..0xCF
|
||||
:readsize
|
||||
when 0xFF
|
||||
:sof
|
||||
else
|
||||
:skipframe
|
||||
end
|
||||
when :skipframe
|
||||
skip_chars = @stream.read_int - 2
|
||||
@stream.read(skip_chars)
|
||||
:started
|
||||
when :readsize
|
||||
s = @stream.read(3)
|
||||
height = @stream.read_int
|
||||
width = @stream.read_int
|
||||
width, height = height, width if @exif && @exif.rotated?
|
||||
return [width, height]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def parse_size_for_bmp
|
||||
d = @stream.read(32)[14..28]
|
||||
header = d.unpack("C")[0]
|
||||
|
||||
result = if header == 40
|
||||
d[4..-1].unpack('l<l<')
|
||||
else
|
||||
d[4..8].unpack('SS')
|
||||
end
|
||||
|
||||
# ImageHeight is expressed in pixels. The absolute value is necessary because ImageHeight can be negative
|
||||
[result.first, result.last.abs]
|
||||
end
|
||||
|
||||
class Exif # :nodoc:
|
||||
attr_reader :width, :height
|
||||
def initialize(stream)
|
||||
@stream = stream
|
||||
parse_exif
|
||||
end
|
||||
|
||||
def rotated?
|
||||
@orientation && @orientation >= 5
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_exif_byte_order
|
||||
byte_order = @stream.read(2)
|
||||
case byte_order
|
||||
when 'II'
|
||||
@short, @long = 'v', 'V'
|
||||
when 'MM'
|
||||
@short, @long = 'n', 'N'
|
||||
else
|
||||
raise CannotParseImage
|
||||
end
|
||||
end
|
||||
|
||||
def parse_exif_ifd
|
||||
tag_count = @stream.read(2).unpack(@short)[0]
|
||||
tag_count.downto(1) do
|
||||
type = @stream.read(2).unpack(@short)[0]
|
||||
@stream.read(6)
|
||||
data = @stream.read(2).unpack(@short)[0]
|
||||
case type
|
||||
when 0x0100 # image width
|
||||
@width = data
|
||||
when 0x0101 # image height
|
||||
@height = data
|
||||
when 0x0112 # orientation
|
||||
@orientation = data
|
||||
end
|
||||
if @width && @height && @orientation
|
||||
return # no need to parse more
|
||||
end
|
||||
@stream.read(2)
|
||||
end
|
||||
|
||||
next_offset = @stream.read(4).unpack(@long)[0]
|
||||
relative_offset = next_offset - (@stream.pos - @start_byte)
|
||||
if relative_offset >= 0
|
||||
@stream.read(relative_offset)
|
||||
parse_exif_ifd
|
||||
end
|
||||
end
|
||||
|
||||
def parse_exif
|
||||
@start_byte = @stream.pos
|
||||
|
||||
get_exif_byte_order
|
||||
|
||||
@stream.read(2) # 42
|
||||
|
||||
offset = @stream.read(4).unpack(@long)[0]
|
||||
@stream.read(offset - 8)
|
||||
|
||||
parse_exif_ifd
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def parse_size_for_tiff
|
||||
exif = Exif.new(@stream)
|
||||
if exif.rotated?
|
||||
[exif.height, exif.width]
|
||||
else
|
||||
[exif.width, exif.height]
|
||||
end
|
||||
end
|
||||
|
||||
def parse_size_for_psd
|
||||
@stream.read(26).unpack("x14NN").reverse
|
||||
# see http://stackoverflow.com/questions/5208851/i/41048816#41048816
|
||||
if RUBY_VERSION < "2.2"
|
||||
module URI
|
||||
DEFAULT_PARSER = Parser.new(:HOSTNAME => "(?:(?:[a-zA-Z\\d](?:[-\\_a-zA-Z\\d]*[a-zA-Z\\d])?)\\.)*(?:[a-zA-Z](?:[-\\_a-zA-Z\\d]*[a-zA-Z\\d])?)\\.?")
|
||||
end
|
||||
end
|
||||
|
471
lib/fastimage/fastimage.rb
Normal file
@ -0,0 +1,471 @@
|
||||
require_relative 'fastimage_parsing/image_base'
|
||||
require_relative 'fastimage_parsing/stream_util'
|
||||
|
||||
require_relative 'fastimage_parsing/avif'
|
||||
require_relative 'fastimage_parsing/bmp'
|
||||
require_relative 'fastimage_parsing/exif'
|
||||
require_relative 'fastimage_parsing/fiber_stream'
|
||||
require_relative 'fastimage_parsing/gif'
|
||||
require_relative 'fastimage_parsing/heic'
|
||||
require_relative 'fastimage_parsing/ico'
|
||||
require_relative 'fastimage_parsing/iso_bmff'
|
||||
require_relative 'fastimage_parsing/jpeg'
|
||||
require_relative 'fastimage_parsing/jxl'
|
||||
require_relative 'fastimage_parsing/jxlc'
|
||||
require_relative 'fastimage_parsing/png'
|
||||
require_relative 'fastimage_parsing/psd'
|
||||
require_relative 'fastimage_parsing/svg'
|
||||
require_relative 'fastimage_parsing/tiff'
|
||||
require_relative 'fastimage_parsing/type_parser'
|
||||
require_relative 'fastimage_parsing/webp'
|
||||
|
||||
class FastImage
|
||||
include FastImageParsing
|
||||
|
||||
attr_reader :bytes_read
|
||||
|
||||
class FastImageException < StandardError # :nodoc:
|
||||
end
|
||||
class UnknownImageType < FastImageException # :nodoc:
|
||||
end
|
||||
class ImageFetchFailure < FastImageException # :nodoc:
|
||||
end
|
||||
class SizeNotFound < FastImageException # :nodoc:
|
||||
end
|
||||
class CannotParseImage < FastImageException # :nodoc:
|
||||
end
|
||||
class BadImageURI < FastImageException # :nodoc:
|
||||
end
|
||||
|
||||
DefaultTimeout = 2 unless const_defined?(:DefaultTimeout)
|
||||
|
||||
LocalFileChunkSize = 256 unless const_defined?(:LocalFileChunkSize)
|
||||
|
||||
private
|
||||
|
||||
Parsers = {
|
||||
:bmp => Bmp,
|
||||
:gif => Gif,
|
||||
:jpeg => Jpeg,
|
||||
:png => Png,
|
||||
:tiff => Tiff,
|
||||
:psd => Psd,
|
||||
:heic => Heic,
|
||||
:heif => Heic,
|
||||
:webp => Webp,
|
||||
:svg => Svg,
|
||||
:ico => Ico,
|
||||
:cur => Ico,
|
||||
:jxl => Jxl,
|
||||
:avif => Avif
|
||||
}.freeze
|
||||
|
||||
public
|
||||
|
||||
SUPPORTED_IMAGE_TYPES = Parsers.keys.freeze
|
||||
|
||||
# Returns an array containing the width and height of the image.
|
||||
# It will return nil if the image could not be fetched, or if the image type was not recognised.
|
||||
#
|
||||
# By default there is a timeout of 2 seconds for opening and reading from a remote server.
|
||||
# This can be changed by passing a :timeout => number_of_seconds in the options.
|
||||
#
|
||||
# If you wish FastImage to raise if it cannot size the image for any reason, then pass
|
||||
# :raise_on_failure => true in the options.
|
||||
#
|
||||
# FastImage knows about GIF, JPEG, BMP, TIFF, ICO, CUR, PNG, HEIC/HEIF, AVIF, PSD, SVG, WEBP and JXL files.
|
||||
#
|
||||
# === Example
|
||||
#
|
||||
# require 'fastimage'
|
||||
#
|
||||
# FastImage.size("https://switchstep.com/images/ios.gif")
|
||||
# => [196, 283]
|
||||
# FastImage.size("http://switchstep.com/images/ss_logo.png")
|
||||
# => [300, 300]
|
||||
# FastImage.size("https://upload.wikimedia.org/wikipedia/commons/0/09/Jpeg_thumb_artifacts_test.jpg")
|
||||
# => [1280, 800]
|
||||
# FastImage.size("https://eeweb.engineering.nyu.edu/~yao/EL5123/image/lena_gray.bmp")
|
||||
# => [512, 512]
|
||||
# FastImage.size("test/fixtures/test.jpg")
|
||||
# => [882, 470]
|
||||
# FastImage.size("http://switchstep.com/does_not_exist")
|
||||
# => nil
|
||||
# FastImage.size("http://switchstep.com/does_not_exist", :raise_on_failure=>true)
|
||||
# => raises FastImage::ImageFetchFailure
|
||||
# FastImage.size("http://switchstep.com/images/favicon.ico", :raise_on_failure=>true)
|
||||
# => [16, 16]
|
||||
# FastImage.size("http://switchstep.com/foo.ics", :raise_on_failure=>true)
|
||||
# => raises FastImage::UnknownImageType
|
||||
# FastImage.size("http://switchstep.com/images/favicon.ico", :raise_on_failure=>true, :timeout=>0.01)
|
||||
# => raises FastImage::ImageFetchFailure
|
||||
# FastImage.size("http://switchstep.com/images/faulty.jpg", :raise_on_failure=>true)
|
||||
# => raises FastImage::SizeNotFound
|
||||
#
|
||||
# === Supported options
|
||||
# [:timeout]
|
||||
# Overrides the default timeout of 2 seconds. Applies both to reading from and opening the http connection.
|
||||
# [:raise_on_failure]
|
||||
# If set to true causes an exception to be raised if the image size cannot be found for any reason.
|
||||
#
|
||||
def self.size(uri, options={})
|
||||
new(uri, options).size
|
||||
end
|
||||
|
||||
# Returns an symbol indicating the image type fetched from a uri.
|
||||
# It will return nil if the image could not be fetched, or if the image type was not recognised.
|
||||
#
|
||||
# By default there is a timeout of 2 seconds for opening and reading from a remote server.
|
||||
# This can be changed by passing a :timeout => number_of_seconds in the options.
|
||||
#
|
||||
# If you wish FastImage to raise if it cannot find the type of the image for any reason, then pass
|
||||
# :raise_on_failure => true in the options.
|
||||
#
|
||||
# === Example
|
||||
#
|
||||
# require 'fastimage'
|
||||
#
|
||||
# FastImage.type("https://switchstep.com/images/ios.gif")
|
||||
# => :gif
|
||||
# FastImage.type("http://switchstep.com/images/ss_logo.png")
|
||||
# => :png
|
||||
# FastImage.type("https://upload.wikimedia.org/wikipedia/commons/0/09/Jpeg_thumb_artifacts_test.jpg")
|
||||
# => :jpeg
|
||||
# FastImage.type("https://eeweb.engineering.nyu.edu/~yao/EL5123/image/lena_gray.bmp")
|
||||
# => :bmp
|
||||
# FastImage.type("test/fixtures/test.jpg")
|
||||
# => :jpeg
|
||||
# FastImage.type("http://switchstep.com/does_not_exist")
|
||||
# => nil
|
||||
# File.open("/some/local/file.gif", "r") {|io| FastImage.type(io)}
|
||||
# => :gif
|
||||
# FastImage.type("test/fixtures/test.tiff")
|
||||
# => :tiff
|
||||
# FastImage.type("test/fixtures/test.psd")
|
||||
# => :psd
|
||||
#
|
||||
# === Supported options
|
||||
# [:timeout]
|
||||
# Overrides the default timeout of 2 seconds. Applies both to reading from and opening the http connection.
|
||||
# [:raise_on_failure]
|
||||
# If set to true causes an exception to be raised if the image type cannot be found for any reason.
|
||||
#
|
||||
def self.type(uri, options={})
|
||||
new(uri, options).type
|
||||
end
|
||||
|
||||
# Returns a boolean value indicating the image is animated.
|
||||
# It will return nil if the image could not be fetched, or if the image type was not recognised.
|
||||
#
|
||||
# By default there is a timeout of 2 seconds for opening and reading from a remote server.
|
||||
# This can be changed by passing a :timeout => number_of_seconds in the options.
|
||||
#
|
||||
# If you wish FastImage to raise if it cannot find the type of the image for any reason, then pass
|
||||
# :raise_on_failure => true in the options.
|
||||
#
|
||||
# === Example
|
||||
#
|
||||
# require 'fastimage'
|
||||
#
|
||||
# FastImage.animated?("test/fixtures/test.gif")
|
||||
# => false
|
||||
# FastImage.animated?("test/fixtures/animated.gif")
|
||||
# => true
|
||||
#
|
||||
# === Supported options
|
||||
# [:timeout]
|
||||
# Overrides the default timeout of 2 seconds. Applies both to reading from and opening the http connection.
|
||||
# [:raise_on_failure]
|
||||
# If set to true causes an exception to be raised if the image type cannot be found for any reason.
|
||||
#
|
||||
def self.animated?(uri, options={})
|
||||
new(uri, options).animated
|
||||
end
|
||||
|
||||
def initialize(uri, options={})
|
||||
@uri = uri
|
||||
@options = {
|
||||
:timeout => DefaultTimeout,
|
||||
:raise_on_failure => false,
|
||||
:proxy => nil,
|
||||
:http_header => {}
|
||||
}.merge(options)
|
||||
end
|
||||
|
||||
def type
|
||||
@property = :type
|
||||
fetch unless defined?(@type)
|
||||
@type
|
||||
end
|
||||
|
||||
def size
|
||||
@property = :size
|
||||
begin
|
||||
fetch unless defined?(@size)
|
||||
rescue CannotParseImage
|
||||
end
|
||||
|
||||
raise SizeNotFound if @options[:raise_on_failure] && !@size
|
||||
|
||||
@size
|
||||
end
|
||||
|
||||
def orientation
|
||||
size unless defined?(@size)
|
||||
@orientation ||= 1 if @size
|
||||
end
|
||||
|
||||
def width
|
||||
size && @size[0]
|
||||
end
|
||||
|
||||
def height
|
||||
size && @size[1]
|
||||
end
|
||||
|
||||
def animated
|
||||
@property = :animated
|
||||
fetch unless defined?(@animated)
|
||||
@animated
|
||||
end
|
||||
|
||||
def content_length
|
||||
@property = :content_length
|
||||
fetch unless defined?(@content_length)
|
||||
@content_length
|
||||
end
|
||||
|
||||
# find an appropriate method to fetch the image according to the passed parameter
|
||||
def fetch
|
||||
raise BadImageURI if @uri.nil?
|
||||
|
||||
if @uri.respond_to?(:read)
|
||||
fetch_using_read(@uri)
|
||||
elsif @uri.start_with?('data:')
|
||||
fetch_using_base64(@uri)
|
||||
else
|
||||
begin
|
||||
@parsed_uri = URI.parse(@uri)
|
||||
rescue URI::InvalidURIError
|
||||
fetch_using_file_open
|
||||
else
|
||||
if @parsed_uri.scheme == "http" || @parsed_uri.scheme == "https"
|
||||
fetch_using_http
|
||||
else
|
||||
fetch_using_file_open
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
raise SizeNotFound if @options[:raise_on_failure] && @property == :size && !@size
|
||||
|
||||
rescue Timeout::Error, SocketError, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET,
|
||||
Errno::ENETUNREACH, ImageFetchFailure, Net::HTTPBadResponse, EOFError, Errno::ENOENT,
|
||||
OpenSSL::SSL::SSLError
|
||||
raise ImageFetchFailure if @options[:raise_on_failure]
|
||||
rescue UnknownImageType, BadImageURI, CannotParseImage
|
||||
raise if @options[:raise_on_failure]
|
||||
|
||||
ensure
|
||||
@uri.rewind if @uri.respond_to?(:rewind)
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fetch_using_http
|
||||
@redirect_count = 0
|
||||
|
||||
fetch_using_http_from_parsed_uri
|
||||
end
|
||||
|
||||
# Some invalid locations need escaping
|
||||
def escaped_location(location)
|
||||
begin
|
||||
URI(location)
|
||||
rescue URI::InvalidURIError
|
||||
::URI::DEFAULT_PARSER.escape(location)
|
||||
else
|
||||
location
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_using_http_from_parsed_uri
|
||||
raise ImageFetchFailure unless @parsed_uri.is_a?(URI::HTTP)
|
||||
|
||||
http_header = {'Accept-Encoding' => 'identity'}.merge(@options[:http_header])
|
||||
|
||||
setup_http
|
||||
@http.request_get(@parsed_uri.request_uri, http_header) do |res|
|
||||
if res.is_a?(Net::HTTPRedirection) && @redirect_count < 4
|
||||
@redirect_count += 1
|
||||
begin
|
||||
location = res['Location']
|
||||
raise ImageFetchFailure if location.nil? || location.empty?
|
||||
|
||||
@parsed_uri = URI.join(@parsed_uri, escaped_location(location))
|
||||
rescue URI::InvalidURIError
|
||||
else
|
||||
fetch_using_http_from_parsed_uri
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
raise ImageFetchFailure unless res.is_a?(Net::HTTPSuccess)
|
||||
|
||||
@content_length = res.content_length
|
||||
break if @property == :content_length
|
||||
|
||||
read_fiber = Fiber.new do
|
||||
res.read_body do |str|
|
||||
Fiber.yield str
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
case res['content-encoding']
|
||||
when 'deflate', 'gzip', 'x-gzip'
|
||||
begin
|
||||
gzip = Zlib::GzipReader.new(FiberStream.new(read_fiber))
|
||||
rescue FiberError, Zlib::GzipFile::Error
|
||||
raise CannotParseImage
|
||||
end
|
||||
|
||||
read_fiber = Fiber.new do
|
||||
while data = gzip.readline
|
||||
Fiber.yield data
|
||||
end
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
parse_packets FiberStream.new(read_fiber)
|
||||
|
||||
break # needed to actively quit out of the fetch
|
||||
end
|
||||
end
|
||||
|
||||
def protocol_relative_url?(url)
|
||||
url.start_with?("//")
|
||||
end
|
||||
|
||||
def proxy_uri
|
||||
begin
|
||||
if @options[:proxy]
|
||||
proxy = URI.parse(@options[:proxy])
|
||||
else
|
||||
proxy = ENV['http_proxy'] && ENV['http_proxy'] != "" ? URI.parse(ENV['http_proxy']) : nil
|
||||
end
|
||||
rescue URI::InvalidURIError
|
||||
proxy = nil
|
||||
end
|
||||
proxy
|
||||
end
|
||||
|
||||
def setup_http
|
||||
proxy = proxy_uri
|
||||
|
||||
if proxy
|
||||
@http = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password).new(@parsed_uri.host, @parsed_uri.port)
|
||||
else
|
||||
@http = Net::HTTP.new(@parsed_uri.host, @parsed_uri.port)
|
||||
end
|
||||
@http.use_ssl = (@parsed_uri.scheme == "https")
|
||||
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||
@http.open_timeout = @options[:timeout]
|
||||
@http.read_timeout = @options[:timeout]
|
||||
end
|
||||
|
||||
def fetch_using_read(readable)
|
||||
return @content_length = readable.size if @property == :content_length && readable.respond_to?(:size)
|
||||
|
||||
readable.rewind if readable.respond_to?(:rewind)
|
||||
# Pathnames respond to read, but always return the first
|
||||
# chunk of the file unlike an IO (even though the
|
||||
# docuementation for it refers to IO). Need to supply
|
||||
# an offset in this case.
|
||||
if readable.is_a?(Pathname)
|
||||
read_fiber = Fiber.new do
|
||||
offset = 0
|
||||
while str = readable.read(LocalFileChunkSize, offset)
|
||||
Fiber.yield str
|
||||
offset += LocalFileChunkSize
|
||||
end
|
||||
nil
|
||||
end
|
||||
else
|
||||
read_fiber = Fiber.new do
|
||||
while str = readable.read(LocalFileChunkSize)
|
||||
Fiber.yield str
|
||||
end
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
parse_packets FiberStream.new(read_fiber)
|
||||
end
|
||||
|
||||
def fetch_using_file_open
|
||||
return @content_length = File.size?(@uri) if @property == :content_length
|
||||
|
||||
File.open(@uri) do |s|
|
||||
fetch_using_read(s)
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_using_base64(uri)
|
||||
decoded = begin
|
||||
uri.split(',')[1].unpack("m").first
|
||||
rescue
|
||||
raise CannotParseImage
|
||||
end
|
||||
|
||||
fetch_using_read StringIO.new(decoded)
|
||||
end
|
||||
|
||||
def parse_packets(stream)
|
||||
@stream = stream
|
||||
|
||||
begin
|
||||
@type = TypeParser.new(@stream).type unless defined?(@type)
|
||||
|
||||
result = case @property
|
||||
when :type
|
||||
@type
|
||||
when :size
|
||||
parse_size
|
||||
when :animated
|
||||
parse_animated
|
||||
end
|
||||
|
||||
if result != nil
|
||||
# extract exif orientation if it was found
|
||||
if @property == :size && result.size == 3
|
||||
@orientation = result.pop
|
||||
else
|
||||
@orientation = 1
|
||||
end
|
||||
|
||||
instance_variable_set("@#{@property}", result)
|
||||
else
|
||||
raise CannotParseImage
|
||||
end
|
||||
rescue FiberError
|
||||
raise CannotParseImage
|
||||
end
|
||||
end
|
||||
|
||||
def parser_class
|
||||
klass = Parsers[@type]
|
||||
raise UnknownImageType unless klass
|
||||
klass
|
||||
end
|
||||
|
||||
def parse_size
|
||||
parser_class.new(@stream).dimensions
|
||||
end
|
||||
|
||||
def parse_animated
|
||||
parser_class.new(@stream).animated?
|
||||
end
|
||||
end
|
12
lib/fastimage/fastimage_parsing/avif.rb
Normal file
@ -0,0 +1,12 @@
|
||||
module FastImageParsing
|
||||
class Avif < ImageBase # :nodoc:
|
||||
def dimensions
|
||||
bmff = IsoBmff.new(@stream)
|
||||
[bmff.width, bmff.height]
|
||||
end
|
||||
|
||||
def animated?
|
||||
@stream.peek(12)[4..-1] == "ftypavis"
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fastimage/fastimage_parsing/bmp.rb
Normal file
@ -0,0 +1,17 @@
|
||||
module FastImageParsing
|
||||
class Bmp < ImageBase # :nodoc:
|
||||
def dimensions
|
||||
d = @stream.read(32)[14..28]
|
||||
header = d.unpack("C")[0]
|
||||
|
||||
result = if header == 12
|
||||
d[4..8].unpack('SS')
|
||||
else
|
||||
d[4..-1].unpack('l<l<')
|
||||
end
|
||||
|
||||
# ImageHeight is expressed in pixels. The absolute value is necessary because ImageHeight can be negative
|
||||
[result.first, result.last.abs]
|
||||
end
|
||||
end
|
||||
end
|
76
lib/fastimage/fastimage_parsing/exif.rb
Normal file
@ -0,0 +1,76 @@
|
||||
module FastImageParsing
|
||||
class Exif # :nodoc:
|
||||
attr_reader :width, :height, :orientation
|
||||
|
||||
def initialize(stream)
|
||||
@stream = stream
|
||||
@width, @height, @orientation = nil
|
||||
parse_exif
|
||||
end
|
||||
|
||||
def rotated?
|
||||
@orientation >= 5
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_exif_byte_order
|
||||
byte_order = @stream.read(2)
|
||||
case byte_order
|
||||
when 'II'
|
||||
@short, @long = 'v', 'V'
|
||||
when 'MM'
|
||||
@short, @long = 'n', 'N'
|
||||
else
|
||||
raise FastImage::CannotParseImage
|
||||
end
|
||||
end
|
||||
|
||||
def parse_exif_ifd
|
||||
tag_count = @stream.read(2).unpack(@short)[0]
|
||||
tag_count.downto(1) do
|
||||
type = @stream.read(2).unpack(@short)[0]
|
||||
data_type = @stream.read(2).unpack(@short)[0]
|
||||
@stream.read(4)
|
||||
|
||||
if data_type == 4
|
||||
data = @stream.read(4).unpack(@long)[0]
|
||||
else
|
||||
data = @stream.read(2).unpack(@short)[0]
|
||||
@stream.read(2)
|
||||
end
|
||||
|
||||
case type
|
||||
when 0x0100 # image width
|
||||
@width = data
|
||||
when 0x0101 # image height
|
||||
@height = data
|
||||
when 0x0112 # orientation
|
||||
@orientation = data
|
||||
end
|
||||
if @width && @height && @orientation
|
||||
return # no need to parse more
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def parse_exif
|
||||
@start_byte = @stream.pos
|
||||
|
||||
get_exif_byte_order
|
||||
|
||||
@stream.read(2) # 42
|
||||
|
||||
offset = @stream.read(4).unpack(@long)[0]
|
||||
if @stream.respond_to?(:skip)
|
||||
@stream.skip(offset - 8)
|
||||
else
|
||||
@stream.read(offset - 8)
|
||||
end
|
||||
|
||||
parse_exif_ifd
|
||||
|
||||
@orientation ||= 1
|
||||
end
|
||||
end
|
||||
end
|
58
lib/fastimage/fastimage_parsing/fiber_stream.rb
Normal file
@ -0,0 +1,58 @@
|
||||
module FastImageParsing
|
||||
class FiberStream # :nodoc:
|
||||
include StreamUtil
|
||||
attr_reader :pos
|
||||
|
||||
# read_fiber should return nil if it no longer has anything to return when resumed
|
||||
# so the result of the whole Fiber block should be set to be nil in case yield is no
|
||||
# longer called
|
||||
def initialize(read_fiber)
|
||||
@read_fiber = read_fiber
|
||||
@pos = 0
|
||||
@strpos = 0
|
||||
@str = ''
|
||||
end
|
||||
|
||||
# Peeking beyond the end of the input will raise
|
||||
def peek(n)
|
||||
while @strpos + n > @str.size
|
||||
unused_str = @str[@strpos..-1]
|
||||
|
||||
new_string = @read_fiber.resume
|
||||
raise FastImage::CannotParseImage if !new_string
|
||||
# we are dealing with bytes here, so force the encoding
|
||||
new_string.force_encoding("ASCII-8BIT") if new_string.respond_to? :force_encoding
|
||||
|
||||
@str = unused_str + new_string
|
||||
@strpos = 0
|
||||
end
|
||||
|
||||
@str[@strpos, n]
|
||||
end
|
||||
|
||||
def read(n)
|
||||
result = peek(n)
|
||||
@strpos += n
|
||||
@pos += n
|
||||
result
|
||||
end
|
||||
|
||||
def skip(n)
|
||||
discarded = 0
|
||||
fetched = @str[@strpos..-1].size
|
||||
while n > fetched
|
||||
discarded += @str[@strpos..-1].size
|
||||
new_string = @read_fiber.resume
|
||||
raise FastImage::CannotParseImage if !new_string
|
||||
|
||||
new_string.force_encoding("ASCII-8BIT") if new_string.respond_to? :force_encoding
|
||||
|
||||
fetched += new_string.size
|
||||
@str = new_string
|
||||
@strpos = 0
|
||||
end
|
||||
@strpos = @strpos + n - discarded
|
||||
@pos += n
|
||||
end
|
||||
end
|
||||
end
|
63
lib/fastimage/fastimage_parsing/gif.rb
Normal file
@ -0,0 +1,63 @@
|
||||
module FastImageParsing
|
||||
class Gif < ImageBase # :nodoc:
|
||||
def dimensions
|
||||
@stream.read(11)[6..10].unpack('SS')
|
||||
end
|
||||
|
||||
# Checks for multiple frames
|
||||
def animated?
|
||||
frames = 0
|
||||
|
||||
# "GIF" + version (3) + width (2) + height (2)
|
||||
@stream.skip(10)
|
||||
|
||||
# fields (1) + bg color (1) + pixel ratio (1)
|
||||
fields = @stream.read(3).unpack("CCC")[0]
|
||||
if fields & 0x80 != 0 # Global Color Table
|
||||
# 2 * (depth + 1) colors, each occupying 3 bytes (RGB)
|
||||
@stream.skip(3 * 2 ** ((fields & 0x7) + 1))
|
||||
end
|
||||
|
||||
loop do
|
||||
block_type = @stream.read(1).unpack("C")[0]
|
||||
|
||||
if block_type == 0x21 # Graphic Control Extension
|
||||
# extension type (1) + size (1)
|
||||
size = @stream.read(2).unpack("CC")[1]
|
||||
@stream.skip(size)
|
||||
skip_sub_blocks
|
||||
elsif block_type == 0x2C # Image Descriptor
|
||||
frames += 1
|
||||
return true if frames > 1
|
||||
|
||||
# left position (2) + top position (2) + width (2) + height (2) + fields (1)
|
||||
fields = @stream.read(9).unpack("SSSSC")[4]
|
||||
if fields & 0x80 != 0 # Local Color Table
|
||||
# 2 * (depth + 1) colors, each occupying 3 bytes (RGB)
|
||||
@stream.skip(3 * 2 ** ((fields & 0x7) + 1))
|
||||
end
|
||||
|
||||
@stream.skip(1) # LZW min code size (1)
|
||||
skip_sub_blocks
|
||||
else
|
||||
break # unrecognized block
|
||||
end
|
||||
end
|
||||
|
||||
false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def skip_sub_blocks
|
||||
loop do
|
||||
size = @stream.read(1).unpack("C")[0]
|
||||
if size == 0
|
||||
break
|
||||
else
|
||||
@stream.skip(size)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
8
lib/fastimage/fastimage_parsing/heic.rb
Normal file
@ -0,0 +1,8 @@
|
||||
module FastImageParsing
|
||||
class Heic < ImageBase # :nodoc:
|
||||
def dimensions
|
||||
bmff = IsoBmff.new(@stream)
|
||||
[bmff.width, bmff.height]
|
||||
end
|
||||
end
|
||||
end
|
9
lib/fastimage/fastimage_parsing/ico.rb
Normal file
@ -0,0 +1,9 @@
|
||||
module FastImageParsing
|
||||
class Ico < ImageBase
|
||||
def dimensions
|
||||
icons = @stream.read(6)[4..5].unpack('v').first
|
||||
sizes = icons.times.map { @stream.read(16).unpack('C2').map { |x| x == 0 ? 256 : x } }.sort_by { |w,h| w * h }
|
||||
sizes.last
|
||||
end
|
||||
end
|
||||
end
|
17
lib/fastimage/fastimage_parsing/image_base.rb
Normal file
@ -0,0 +1,17 @@
|
||||
module FastImageParsing
|
||||
class ImageBase # :nodoc:
|
||||
def initialize(stream)
|
||||
@stream = stream
|
||||
end
|
||||
|
||||
# Implement in subclasses
|
||||
def dimensions
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
# Implement in subclasses if appropriate
|
||||
def animated?
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
176
lib/fastimage/fastimage_parsing/iso_bmff.rb
Normal file
@ -0,0 +1,176 @@
|
||||
module FastImageParsing
|
||||
# HEIC/AVIF are a special case of the general ISO_BMFF format, in which all data is encapsulated in typed boxes,
|
||||
# with a mandatory ftyp box that is used to indicate particular file types. Is composed of nested "boxes". Each
|
||||
# box has a header composed of
|
||||
# - Size (32 bit integer)
|
||||
# - Box type (4 chars)
|
||||
# - Extended size: only if size === 1, the type field is followed by 64 bit integer of extended size
|
||||
# - Payload: Type-dependent
|
||||
class IsoBmff # :nodoc:
|
||||
attr_reader :width, :height
|
||||
|
||||
def initialize(stream)
|
||||
@stream = stream
|
||||
@width, @height = nil
|
||||
parse_isobmff
|
||||
end
|
||||
|
||||
def parse_isobmff
|
||||
@rotation = 0
|
||||
@max_size = nil
|
||||
@primary_box = nil
|
||||
@ipma_boxes = []
|
||||
@ispe_boxes = []
|
||||
@final_size = nil
|
||||
|
||||
catch :finish do
|
||||
read_boxes!
|
||||
end
|
||||
|
||||
if [90, 270].include?(@rotation)
|
||||
@final_size.reverse!
|
||||
end
|
||||
|
||||
@width, @height = @final_size
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Format specs: https://www.loc.gov/preservation/digital/formats/fdd/fdd000525.shtml
|
||||
|
||||
# If you need to inspect a heic/heif file, use
|
||||
# https://gpac.github.io/mp4box.js/test/filereader.html
|
||||
def read_boxes!(max_read_bytes = nil)
|
||||
end_pos = max_read_bytes.nil? ? nil : @stream.pos + max_read_bytes
|
||||
index = 0
|
||||
|
||||
loop do
|
||||
return if end_pos && @stream.pos >= end_pos
|
||||
|
||||
box_type, box_size = read_box_header!
|
||||
|
||||
case box_type
|
||||
when "meta"
|
||||
handle_meta_box(box_size)
|
||||
when "pitm"
|
||||
handle_pitm_box(box_size)
|
||||
when "ipma"
|
||||
handle_ipma_box(box_size)
|
||||
when "hdlr"
|
||||
handle_hdlr_box(box_size)
|
||||
when "iprp", "ipco"
|
||||
read_boxes!(box_size)
|
||||
when "irot"
|
||||
handle_irot_box
|
||||
when "ispe"
|
||||
handle_ispe_box(box_size, index)
|
||||
when "mdat"
|
||||
@stream.skip(box_size)
|
||||
when "jxlc"
|
||||
handle_jxlc_box(box_size)
|
||||
else
|
||||
@stream.skip(box_size)
|
||||
end
|
||||
|
||||
index += 1
|
||||
end
|
||||
end
|
||||
|
||||
def handle_irot_box
|
||||
@rotation = (read_uint8! & 0x3) * 90
|
||||
end
|
||||
|
||||
def handle_ispe_box(box_size, index)
|
||||
throw :finish if box_size < 12
|
||||
|
||||
data = @stream.read(box_size)
|
||||
width, height = data[4...12].unpack("N2")
|
||||
@ispe_boxes << { index: index, size: [width, height] }
|
||||
end
|
||||
|
||||
def handle_hdlr_box(box_size)
|
||||
throw :finish if box_size < 12
|
||||
|
||||
data = @stream.read(box_size)
|
||||
throw :finish if data[8...12] != "pict"
|
||||
end
|
||||
|
||||
def handle_ipma_box(box_size)
|
||||
@stream.read(3)
|
||||
flags3 = read_uint8!
|
||||
entries_count = read_uint32!
|
||||
|
||||
entries_count.times do
|
||||
id = read_uint16!
|
||||
essen_count = read_uint8!
|
||||
|
||||
essen_count.times do
|
||||
property_index = read_uint8! & 0x7F
|
||||
|
||||
if flags3 & 1 == 1
|
||||
property_index = (property_index << 7) + read_uint8!
|
||||
end
|
||||
|
||||
@ipma_boxes << { id: id, property_index: property_index - 1 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def handle_pitm_box(box_size)
|
||||
data = @stream.read(box_size)
|
||||
@primary_box = data[4...6].unpack("S>")[0]
|
||||
end
|
||||
|
||||
def handle_meta_box(box_size)
|
||||
throw :finish if box_size < 4
|
||||
|
||||
@stream.read(4)
|
||||
read_boxes!(box_size - 4)
|
||||
|
||||
throw :finish if !@primary_box
|
||||
|
||||
primary_indices = @ipma_boxes
|
||||
.select { |box| box[:id] == @primary_box }
|
||||
.map { |box| box[:property_index] }
|
||||
|
||||
ispe_box = @ispe_boxes.find do |box|
|
||||
primary_indices.include?(box[:index])
|
||||
end
|
||||
|
||||
if ispe_box
|
||||
@final_size = ispe_box[:size]
|
||||
end
|
||||
|
||||
throw :finish
|
||||
end
|
||||
|
||||
def handle_jxlc_box(box_size)
|
||||
jxlc = Jxlc.new(@stream)
|
||||
@final_size = [jxlc.width, jxlc.height]
|
||||
throw :finish
|
||||
end
|
||||
|
||||
def read_box_header!
|
||||
size = read_uint32!
|
||||
type = @stream.read(4)
|
||||
size = read_uint64! - 8 if size == 1
|
||||
[type, size - 8]
|
||||
end
|
||||
|
||||
def read_uint8!
|
||||
@stream.read(1).unpack("C")[0]
|
||||
end
|
||||
|
||||
def read_uint16!
|
||||
@stream.read(2).unpack("S>")[0]
|
||||
end
|
||||
|
||||
def read_uint32!
|
||||
@stream.read(4).unpack("N")[0]
|
||||
end
|
||||
|
||||
def read_uint64!
|
||||
@stream.read(8).unpack("Q>")[0]
|
||||
end
|
||||
end
|
||||
end
|
52
lib/fastimage/fastimage_parsing/jpeg.rb
Normal file
@ -0,0 +1,52 @@
|
||||
module FastImageParsing
|
||||
class IOStream < SimpleDelegator # :nodoc:
|
||||
include StreamUtil
|
||||
end
|
||||
|
||||
class Jpeg < ImageBase # :nodoc:
|
||||
def dimensions
|
||||
exif = nil
|
||||
state = nil
|
||||
loop do
|
||||
state = case state
|
||||
when nil
|
||||
@stream.skip(2)
|
||||
:started
|
||||
when :started
|
||||
@stream.read_byte == 0xFF ? :sof : :started
|
||||
when :sof
|
||||
case @stream.read_byte
|
||||
when 0xe1 # APP1
|
||||
skip_chars = @stream.read_int - 2
|
||||
data = @stream.read(skip_chars)
|
||||
io = StringIO.new(data)
|
||||
if io.read(4) == "Exif"
|
||||
io.read(2)
|
||||
new_exif = Exif.new(IOStream.new(io)) rescue nil
|
||||
exif ||= new_exif # only use the first APP1 segment
|
||||
end
|
||||
:started
|
||||
when 0xe0..0xef
|
||||
:skipframe
|
||||
when 0xC0..0xC3, 0xC5..0xC7, 0xC9..0xCB, 0xCD..0xCF
|
||||
:readsize
|
||||
when 0xFF
|
||||
:sof
|
||||
else
|
||||
:skipframe
|
||||
end
|
||||
when :skipframe
|
||||
skip_chars = @stream.read_int - 2
|
||||
@stream.skip(skip_chars)
|
||||
:started
|
||||
when :readsize
|
||||
@stream.skip(3)
|
||||
height = @stream.read_int
|
||||
width = @stream.read_int
|
||||
width, height = height, width if exif && exif.rotated?
|
||||
return [width, height, exif ? exif.orientation : 1]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
13
lib/fastimage/fastimage_parsing/jxl.rb
Normal file
@ -0,0 +1,13 @@
|
||||
module FastImageParsing
|
||||
class Jxl < ImageBase # :nodoc:
|
||||
def dimensions
|
||||
if @stream.peek(2) == "\xFF\x0A".b
|
||||
jxlc = Jxlc.new(@stream)
|
||||
[jxlc.width, jxlc.height]
|
||||
else
|
||||
bmff = IsoBmff.new(@stream)
|
||||
[bmff.width, bmff.height]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
75
lib/fastimage/fastimage_parsing/jxlc.rb
Normal file
@ -0,0 +1,75 @@
|
||||
module FastImageParsing
|
||||
class Jxlc # :nodoc:
|
||||
attr_reader :width, :height
|
||||
|
||||
LENGTHS = [9, 13, 18, 30]
|
||||
MULTIPLIERS = [1, 1.2, Rational(4, 3), 1.5, Rational(16, 9), 1.25, 2]
|
||||
|
||||
def initialize(stream)
|
||||
@stream = stream
|
||||
@width, @height´ = nil
|
||||
@bit_counter = 0
|
||||
parse_jxlc
|
||||
end
|
||||
|
||||
def parse_jxlc
|
||||
@words = @stream.read(6)[2..5].unpack('vv')
|
||||
|
||||
# small mode allows for values <= 256 that are divisible by 8
|
||||
small = get_bits(1)
|
||||
if small == 1
|
||||
y = (get_bits(5) + 1) * 8
|
||||
x = x_from_ratio(y)
|
||||
if !x
|
||||
x = (get_bits(5) + 1) * 8
|
||||
end
|
||||
@width, @height = x, y
|
||||
return
|
||||
end
|
||||
|
||||
len = LENGTHS[get_bits(2)]
|
||||
y = get_bits(len) + 1
|
||||
x = x_from_ratio(y)
|
||||
if !x
|
||||
len = LENGTHS[get_bits(2)]
|
||||
x = get_bits(len) + 1
|
||||
end
|
||||
@width, @height = x, y
|
||||
end
|
||||
|
||||
def get_bits(size)
|
||||
if @words.size < (@bit_counter + size) / 16 + 1
|
||||
@words += @stream.read(4).unpack('vv')
|
||||
end
|
||||
|
||||
dest_pos = 0
|
||||
dest = 0
|
||||
size.times do
|
||||
word = @bit_counter / 16
|
||||
source_pos = @bit_counter % 16
|
||||
dest |= ((@words[word] & (1 << source_pos)) > 0 ? 1 : 0) << dest_pos
|
||||
dest_pos += 1
|
||||
@bit_counter += 1
|
||||
end
|
||||
dest
|
||||
end
|
||||
|
||||
def x_from_ratio(y)
|
||||
ratio = get_bits(3)
|
||||
if ratio == 0
|
||||
return nil
|
||||
else
|
||||
return (y * MULTIPLIERS[ratio - 1]).to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def parse_size_for_jxl
|
||||
if @stream.peek(2) == "\xFF\x0A".b
|
||||
JXL.new(@stream).read_size_header
|
||||
else
|
||||
bmff = IsoBmff.new(@stream)
|
||||
bmff.width_and_height
|
||||
end
|
||||
end
|
||||
end
|
26
lib/fastimage/fastimage_parsing/png.rb
Normal file
@ -0,0 +1,26 @@
|
||||
module FastImageParsing
|
||||
class Png < ImageBase # :nodoc:
|
||||
def dimensions
|
||||
@stream.read(25)[16..24].unpack('NN')
|
||||
end
|
||||
|
||||
def animated?
|
||||
# Signature (8) + IHDR chunk (4 + 4 + 13 + 4)
|
||||
@stream.read(33)
|
||||
|
||||
loop do
|
||||
length = @stream.read(4).unpack("L>")[0]
|
||||
type = @stream.read(4)
|
||||
|
||||
case type
|
||||
when "acTL"
|
||||
return true
|
||||
when "IDAT"
|
||||
return false
|
||||
end
|
||||
|
||||
@stream.skip(length + 4)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
7
lib/fastimage/fastimage_parsing/psd.rb
Normal file
@ -0,0 +1,7 @@
|
||||
module FastImageParsing
|
||||
class Psd < ImageBase # :nodoc:
|
||||
def dimensions
|
||||
@stream.read(26).unpack("x14NN").reverse
|
||||
end
|
||||
end
|
||||
end
|
19
lib/fastimage/fastimage_parsing/stream_util.rb
Normal file
@ -0,0 +1,19 @@
|
||||
module FastImageParsing
|
||||
module StreamUtil # :nodoc:
|
||||
def read_byte
|
||||
read(1)[0].ord
|
||||
end
|
||||
|
||||
def read_int
|
||||
read(2).unpack('n')[0]
|
||||
end
|
||||
|
||||
def read_string_int
|
||||
value = []
|
||||
while read(1) =~ /(\d)/
|
||||
value << $1
|
||||
end
|
||||
value.join.to_i
|
||||
end
|
||||
end
|
||||
end
|
69
lib/fastimage/fastimage_parsing/svg.rb
Normal file
@ -0,0 +1,69 @@
|
||||
module FastImageParsing
|
||||
class Svg < ImageBase # :nodoc:
|
||||
def dimensions
|
||||
@width, @height, @ratio, @viewbox_width, @viewbox_height = nil
|
||||
|
||||
parse_svg
|
||||
|
||||
if @width && @height
|
||||
[@width, @height]
|
||||
elsif @width && @ratio
|
||||
[@width, @width / @ratio]
|
||||
elsif @height && @ratio
|
||||
[@height * @ratio, @height]
|
||||
elsif @viewbox_width && @viewbox_height
|
||||
[@viewbox_width, @viewbox_height]
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def parse_svg
|
||||
attr_name = []
|
||||
state = nil
|
||||
|
||||
while (char = @stream.read(1)) && state != :stop do
|
||||
case char
|
||||
when "="
|
||||
if attr_name.join =~ /width/i
|
||||
@stream.read(1)
|
||||
@width = @stream.read_string_int
|
||||
return if @height
|
||||
elsif attr_name.join =~ /height/i
|
||||
@stream.read(1)
|
||||
@height = @stream.read_string_int
|
||||
return if @width
|
||||
elsif attr_name.join =~ /viewbox/i
|
||||
values = attr_value.split(/\s/)
|
||||
if values[2].to_f > 0 && values[3].to_f > 0
|
||||
@ratio = values[2].to_f / values[3].to_f
|
||||
@viewbox_width = values[2].to_i
|
||||
@viewbox_height = values[3].to_i
|
||||
end
|
||||
end
|
||||
when /\w/
|
||||
attr_name << char
|
||||
when "<"
|
||||
attr_name = [char]
|
||||
when ">"
|
||||
state = :stop if state == :started
|
||||
else
|
||||
state = :started if attr_name.join == "<svg"
|
||||
attr_name.clear
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def attr_value
|
||||
@stream.read(1)
|
||||
|
||||
value = []
|
||||
while @stream.read(1) =~ /([^"])/
|
||||
value << $1
|
||||
end
|
||||
value.join
|
||||
end
|
||||
end
|
||||
end
|
16
lib/fastimage/fastimage_parsing/tiff.rb
Normal file
@ -0,0 +1,16 @@
|
||||
module FastImageParsing
|
||||
class Tiff < ImageBase # :nodoc:
|
||||
def initialize(stream)
|
||||
@stream = stream
|
||||
end
|
||||
|
||||
def dimensions
|
||||
exif = Exif.new(@stream)
|
||||
if exif.rotated?
|
||||
[exif.height, exif.width, exif.orientation]
|
||||
else
|
||||
[exif.width, exif.height, exif.orientation]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
69
lib/fastimage/fastimage_parsing/type_parser.rb
Normal file
@ -0,0 +1,69 @@
|
||||
module FastImageParsing
|
||||
class TypeParser
|
||||
def initialize(stream)
|
||||
@stream = stream
|
||||
end
|
||||
|
||||
# type will use peek to get enough bytes to determing the type of the image
|
||||
def type
|
||||
parsed_type = case @stream.peek(2)
|
||||
when "BM"
|
||||
:bmp
|
||||
when "GI"
|
||||
:gif
|
||||
when 0xff.chr + 0xd8.chr
|
||||
:jpeg
|
||||
when 0x89.chr + "P"
|
||||
:png
|
||||
when "II", "MM"
|
||||
case @stream.peek(11)[8..10]
|
||||
when "APC", "CR\002"
|
||||
nil # do not recognise CRW or CR2 as tiff
|
||||
else
|
||||
:tiff
|
||||
end
|
||||
when '8B'
|
||||
:psd
|
||||
when "\xFF\x0A".b
|
||||
:jxl
|
||||
when "\0\0"
|
||||
case @stream.peek(3).bytes.to_a.last
|
||||
when 0
|
||||
# http://www.ftyps.com/what.html
|
||||
case @stream.peek(12)[4..-1]
|
||||
when "ftypavif"
|
||||
:avif
|
||||
when "ftypavis"
|
||||
:avif
|
||||
when "ftypheic"
|
||||
:heic
|
||||
when "ftypmif1"
|
||||
:heif
|
||||
else
|
||||
if @stream.peek(7)[4..-1] == 'JXL'
|
||||
:jxl
|
||||
end
|
||||
end
|
||||
# ico has either a 1 (for ico format) or 2 (for cursor) at offset 3
|
||||
when 1 then :ico
|
||||
when 2 then :cur
|
||||
end
|
||||
when "RI"
|
||||
:webp if @stream.peek(12)[8..11] == "WEBP"
|
||||
when "<s"
|
||||
:svg if @stream.peek(4) == "<svg"
|
||||
when /\s\s|\s<|<[?!]/, 0xef.chr + 0xbb.chr
|
||||
# Peek 10 more chars each time, and if end of file is reached just raise
|
||||
# unknown. We assume the <svg tag cannot be within 10 chars of the end of
|
||||
# the file, and is within the first 1000 chars.
|
||||
begin
|
||||
:svg if (1..100).detect {|n| @stream.peek(10 * n).include?("<svg")}
|
||||
rescue FiberError, FastImage::CannotParseImage
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
parsed_type or raise FastImage::UnknownImageType
|
||||
end
|
||||
end
|
||||
end
|
60
lib/fastimage/fastimage_parsing/webp.rb
Normal file
@ -0,0 +1,60 @@
|
||||
module FastImageParsing
|
||||
class Webp < ImageBase # :nodoc:
|
||||
def dimensions
|
||||
vp8 = @stream.read(16)[12..15]
|
||||
_len = @stream.read(4).unpack("V")
|
||||
case vp8
|
||||
when "VP8 "
|
||||
parse_size_vp8
|
||||
when "VP8L"
|
||||
parse_size_vp8l
|
||||
when "VP8X"
|
||||
parse_size_vp8x
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def animated?
|
||||
vp8 = @stream.read(16)[12..15]
|
||||
_len = @stream.read(4).unpack("V")
|
||||
case vp8
|
||||
when "VP8 "
|
||||
false
|
||||
when "VP8L"
|
||||
false
|
||||
when "VP8X"
|
||||
flags = @stream.read(4).unpack("C")[0]
|
||||
flags & 2 > 0
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def parse_size_vp8
|
||||
w, h = @stream.read(10).unpack("@6vv")
|
||||
[w & 0x3fff, h & 0x3fff]
|
||||
end
|
||||
|
||||
def parse_size_vp8l
|
||||
@stream.skip(1) # 0x2f
|
||||
b1, b2, b3, b4 = @stream.read(4).bytes.to_a
|
||||
[1 + (((b2 & 0x3f) << 8) | b1), 1 + (((b4 & 0xF) << 10) | (b3 << 2) | ((b2 & 0xC0) >> 6))]
|
||||
end
|
||||
|
||||
def parse_size_vp8x
|
||||
flags = @stream.read(4).unpack("C")[0]
|
||||
b1, b2, b3, b4, b5, b6 = @stream.read(6).unpack("CCCCCC")
|
||||
width, height = 1 + b1 + (b2 << 8) + (b3 << 16), 1 + b4 + (b5 << 8) + (b6 << 16)
|
||||
|
||||
if flags & 8 > 0 # exif
|
||||
# parse exif for orientation
|
||||
# TODO: find or create test images for this
|
||||
end
|
||||
|
||||
[width, height]
|
||||
end
|
||||
end
|
||||
end
|
@ -1,67 +0,0 @@
|
||||
# Poor Man's Fiber (API compatible Thread based Fiber implementation for Ruby 1.8)
|
||||
# (c) 2008 Aman Gupta (tmm1)
|
||||
|
||||
unless defined? Fiber
|
||||
require 'thread'
|
||||
|
||||
class FiberError < StandardError; # :nodoc:
|
||||
end
|
||||
|
||||
class Fiber # :nodoc:
|
||||
def initialize
|
||||
raise ArgumentError, 'new Fiber requires a block' unless block_given?
|
||||
|
||||
@yield = Queue.new
|
||||
@resume = Queue.new
|
||||
|
||||
@thread = Thread.new{ @yield.push [yield(*@resume.pop)] }
|
||||
@thread.abort_on_exception = true
|
||||
@thread[:fiber] = self
|
||||
end
|
||||
attr_reader :thread
|
||||
|
||||
def resume *args
|
||||
raise FiberError, 'dead fiber called' unless @thread.alive?
|
||||
@resume.push(args)
|
||||
result = @yield.pop
|
||||
result.size > 1 ? result : result.first
|
||||
end
|
||||
|
||||
def yield *args
|
||||
@yield.push(args)
|
||||
result = @resume.pop
|
||||
result.size > 1 ? result : result.first
|
||||
end
|
||||
|
||||
def self.yield *args
|
||||
if fiber = Thread.current[:fiber]
|
||||
fiber.yield(*args)
|
||||
else
|
||||
raise FiberError, 'not inside a fiber'
|
||||
end
|
||||
end
|
||||
|
||||
def self.current
|
||||
if Thread.current == Thread.main
|
||||
return Thread.main[:fiber] ||= RootFiber.new
|
||||
end
|
||||
|
||||
Thread.current[:fiber] or raise FiberError, 'not inside a fiber'
|
||||
end
|
||||
|
||||
def inspect
|
||||
"#<#{self.class}:0x#{self.object_id.to_s(16)}>"
|
||||
end
|
||||
end
|
||||
|
||||
class RootFiber < Fiber # :nodoc:
|
||||
def initialize
|
||||
# XXX: what is a root fiber anyway?
|
||||
end
|
||||
|
||||
def self.yield *args
|
||||
raise FiberError, "can't yield from root fiber"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
5
lib/fastimage/version.rb
Normal file
@ -0,0 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class FastImage
|
||||
VERSION = '2.4.0'
|
||||
end
|
@ -1,436 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
|
||||
|
||||
<title>class FastImage - RDoc Documentation</title>
|
||||
|
||||
<link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
|
||||
|
||||
<script type="text/javascript">
|
||||
var rdoc_rel_prefix = "./";
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
|
||||
|
||||
|
||||
<body id="top" class="class">
|
||||
<nav id="metadata">
|
||||
<nav id="home-section" class="section">
|
||||
<h3 class="section-header">
|
||||
<a href="./index.html">Home</a>
|
||||
<a href="./table_of_contents.html#classes">Classes</a>
|
||||
<a href="./table_of_contents.html#methods">Methods</a>
|
||||
</h3>
|
||||
</nav>
|
||||
|
||||
|
||||
<nav id="search-section" class="section project-section" class="initially-hidden">
|
||||
<form action="#" method="get" accept-charset="utf-8">
|
||||
<h3 class="section-header">
|
||||
<input type="text" name="search" placeholder="Search" id="search-field"
|
||||
title="Type to search, Up and Down to navigate, Enter to load">
|
||||
</h3>
|
||||
</form>
|
||||
|
||||
<ul id="search-results" class="initially-hidden"></ul>
|
||||
</nav>
|
||||
|
||||
|
||||
|
||||
|
||||
<div id="file-metadata">
|
||||
<nav id="file-list-section" class="section">
|
||||
<h3 class="section-header">Defined In</h3>
|
||||
<ul>
|
||||
<li>lib/fastimage.rb
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div id="class-metadata">
|
||||
|
||||
<nav id="parent-class-section" class="section">
|
||||
<h3 class="section-header">Parent</h3>
|
||||
|
||||
<p class="link">Object
|
||||
|
||||
</nav>
|
||||
|
||||
|
||||
|
||||
<!-- Method Quickref -->
|
||||
<nav id="method-list-section" class="section">
|
||||
<h3 class="section-header">Methods</h3>
|
||||
|
||||
<ul class="link-list">
|
||||
|
||||
<li ><a href="#method-c-new">::new</a>
|
||||
|
||||
<li ><a href="#method-c-size">::size</a>
|
||||
|
||||
<li ><a href="#method-c-type">::type</a>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="project-metadata">
|
||||
|
||||
<nav id="classindex-section" class="section project-section">
|
||||
<h3 class="section-header">Class and Module Index</h3>
|
||||
|
||||
<ul class="link-list">
|
||||
|
||||
<li><a href="./FastImage.html">FastImage</a>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div id="documentation">
|
||||
<h1 class="class">class FastImage</h1>
|
||||
|
||||
<div id="description" class="description">
|
||||
|
||||
</div><!-- description -->
|
||||
|
||||
|
||||
|
||||
|
||||
<section id="5Buntitled-5D" class="documentation-section">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- Constants -->
|
||||
<section id="constants-list" class="section">
|
||||
<h3 class="section-header">Constants</h3>
|
||||
<dl>
|
||||
|
||||
<dt id="DefaultTimeout">DefaultTimeout
|
||||
|
||||
<dd class="description">
|
||||
|
||||
|
||||
<dt id="LocalFileChunkSize">LocalFileChunkSize
|
||||
|
||||
<dd class="description">
|
||||
|
||||
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
<!-- Attributes -->
|
||||
<section id="attribute-method-details" class="method-section section">
|
||||
<h3 class="section-header">Attributes</h3>
|
||||
|
||||
|
||||
<div id="attribute-i-bytes_read" class="method-detail">
|
||||
<div class="method-heading attribute-method-heading">
|
||||
<span class="method-name">bytes_read</span><span
|
||||
class="attribute-access-type">[R]</span>
|
||||
</div>
|
||||
|
||||
<div class="method-description">
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="attribute-i-size" class="method-detail">
|
||||
<div class="method-heading attribute-method-heading">
|
||||
<span class="method-name">size</span><span
|
||||
class="attribute-access-type">[R]</span>
|
||||
</div>
|
||||
|
||||
<div class="method-description">
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="attribute-i-type" class="method-detail">
|
||||
<div class="method-heading attribute-method-heading">
|
||||
<span class="method-name">type</span><span
|
||||
class="attribute-access-type">[R]</span>
|
||||
</div>
|
||||
|
||||
<div class="method-description">
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section><!-- attribute-method-details -->
|
||||
|
||||
|
||||
<!-- Methods -->
|
||||
|
||||
<section id="public-class-5Buntitled-5D-method-details" class="method-section section">
|
||||
<h3 class="section-header">Public Class Methods</h3>
|
||||
|
||||
|
||||
<div id="method-c-new" class="method-detail ">
|
||||
|
||||
<div class="method-heading">
|
||||
<span class="method-name">new</span><span
|
||||
class="method-args">(uri, options={})</span>
|
||||
|
||||
<span class="method-click-advice">click to toggle source</span>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="method-description">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="method-source-code" id="new-source">
|
||||
<pre><span class="ruby-comment"># File lib/fastimage.rb, line 157</span>
|
||||
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">options</span>={})
|
||||
<span class="ruby-ivar">@property</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:type_only</span>] <span class="ruby-operator">?</span> <span class="ruby-value">:type</span> <span class="ruby-operator">:</span> <span class="ruby-value">:size</span>
|
||||
<span class="ruby-ivar">@timeout</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:timeout</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">DefaultTimeout</span>
|
||||
<span class="ruby-ivar">@uri</span> = <span class="ruby-identifier">uri</span>
|
||||
|
||||
<span class="ruby-keyword">if</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:read</span>)
|
||||
<span class="ruby-identifier">fetch_using_read</span>(<span class="ruby-identifier">uri</span>)
|
||||
<span class="ruby-keyword">else</span>
|
||||
<span class="ruby-keyword">begin</span>
|
||||
<span class="ruby-ivar">@parsed_uri</span> = <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">uri</span>)
|
||||
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">Addressable</span><span class="ruby-operator">::</span><span class="ruby-constant">URI</span><span class="ruby-operator">::</span><span class="ruby-constant">InvalidURIError</span>
|
||||
<span class="ruby-identifier">fetch_using_open_uri</span>
|
||||
<span class="ruby-keyword">else</span>
|
||||
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@parsed_uri</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">==</span> <span class="ruby-string">"http"</span> <span class="ruby-operator">||</span> <span class="ruby-ivar">@parsed_uri</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">==</span> <span class="ruby-string">"https"</span>
|
||||
<span class="ruby-identifier">fetch_using_http</span>
|
||||
<span class="ruby-keyword">else</span>
|
||||
<span class="ruby-identifier">fetch_using_open_uri</span>
|
||||
<span class="ruby-keyword">end</span>
|
||||
<span class="ruby-keyword">end</span>
|
||||
<span class="ruby-keyword">end</span>
|
||||
|
||||
<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">rewind</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:rewind</span>)
|
||||
|
||||
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SizeNotFound</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:raise_on_failure</span>] <span class="ruby-operator">&&</span> <span class="ruby-ivar">@property</span> <span class="ruby-operator">==</span> <span class="ruby-value">:size</span> <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@size</span>
|
||||
|
||||
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">Timeout</span><span class="ruby-operator">::</span><span class="ruby-constant">Error</span>, <span class="ruby-constant">SocketError</span>, <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ECONNREFUSED</span>, <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">EHOSTUNREACH</span>, <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ECONNRESET</span>,
|
||||
<span class="ruby-constant">ImageFetchFailure</span>, <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTPBadResponse</span>, <span class="ruby-constant">EOFError</span>, <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ENOENT</span>
|
||||
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ImageFetchFailure</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:raise_on_failure</span>]
|
||||
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">NoMethodError</span> <span class="ruby-comment"># 1.8.7p248 can raise this due to a net/http bug</span>
|
||||
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ImageFetchFailure</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:raise_on_failure</span>]
|
||||
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">UnknownImageType</span>
|
||||
<span class="ruby-identifier">raise</span> <span class="ruby-constant">UnknownImageType</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:raise_on_failure</span>]
|
||||
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">CannotParseImage</span>
|
||||
<span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:raise_on_failure</span>]
|
||||
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@property</span> <span class="ruby-operator">==</span> <span class="ruby-value">:size</span>
|
||||
<span class="ruby-identifier">raise</span> <span class="ruby-constant">SizeNotFound</span>
|
||||
<span class="ruby-keyword">else</span>
|
||||
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ImageFetchFailure</span>
|
||||
<span class="ruby-keyword">end</span>
|
||||
<span class="ruby-keyword">end</span>
|
||||
|
||||
<span class="ruby-keyword">end</span></pre>
|
||||
</div><!-- new-source -->
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</div><!-- new-method -->
|
||||
|
||||
|
||||
<div id="method-c-size" class="method-detail ">
|
||||
|
||||
<div class="method-heading">
|
||||
<span class="method-name">size</span><span
|
||||
class="method-args">(uri, options={})</span>
|
||||
|
||||
<span class="method-click-advice">click to toggle source</span>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="method-description">
|
||||
|
||||
<p>Returns an array containing the width and height of the image. It will
|
||||
return nil if the image could not be fetched, or if the image type was not
|
||||
recognised.</p>
|
||||
|
||||
<p>By default there is a timeout of 2 seconds for opening and reading from a
|
||||
remote server. This can be changed by passing a :timeout =>
|
||||
number_of_seconds in the options.</p>
|
||||
|
||||
<p>If you wish <a href="FastImage.html">FastImage</a> to raise if it cannot
|
||||
size the image for any reason, then pass :raise_on_failure => true in
|
||||
the options.</p>
|
||||
|
||||
<p><a href="FastImage.html">FastImage</a> knows about GIF, JPEG, BMP, TIFF,
|
||||
PNG and PSD files.</p>
|
||||
|
||||
<h3 id="method-c-size-label-Example">Example<span><a href="#method-c-size-label-Example">¶</a> <a href="#documentation">↑</a></span></h3>
|
||||
|
||||
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'fastimage'</span>
|
||||
|
||||
<span class="ruby-constant">FastImage</span>.<span class="ruby-identifier">size</span>(<span class="ruby-string">"http://stephensykes.com/images/ss.com_x.gif"</span>)
|
||||
=<span class="ruby-operator">></span> [<span class="ruby-value">266</span>, <span class="ruby-value">56</span>]
|
||||
<span class="ruby-constant">FastImage</span>.<span class="ruby-identifier">size</span>(<span class="ruby-string">"http://stephensykes.com/images/pngimage"</span>)
|
||||
=<span class="ruby-operator">></span> [<span class="ruby-value">16</span>, <span class="ruby-value">16</span>]
|
||||
<span class="ruby-constant">FastImage</span>.<span class="ruby-identifier">size</span>(<span class="ruby-string">"http://farm4.static.flickr.com/3023/3047236863_9dce98b836.jpg"</span>)
|
||||
=<span class="ruby-operator">></span> [<span class="ruby-value">500</span>, <span class="ruby-value">375</span>]
|
||||
<span class="ruby-constant">FastImage</span>.<span class="ruby-identifier">size</span>(<span class="ruby-string">"http://www-ece.rice.edu/~wakin/images/lena512.bmp"</span>)
|
||||
=<span class="ruby-operator">></span> [<span class="ruby-value">512</span>, <span class="ruby-value">512</span>]
|
||||
<span class="ruby-constant">FastImage</span>.<span class="ruby-identifier">size</span>(<span class="ruby-string">"test/fixtures/test.jpg"</span>)
|
||||
=<span class="ruby-operator">></span> [<span class="ruby-value">882</span>, <span class="ruby-value">470</span>]
|
||||
<span class="ruby-constant">FastImage</span>.<span class="ruby-identifier">size</span>(<span class="ruby-string">"http://pennysmalls.com/does_not_exist"</span>)
|
||||
=<span class="ruby-operator">></span> <span class="ruby-keyword">nil</span>
|
||||
<span class="ruby-constant">FastImage</span>.<span class="ruby-identifier">size</span>(<span class="ruby-string">"http://pennysmalls.com/does_not_exist"</span>, :<span class="ruby-identifier">raise_on_failure=</span><span class="ruby-operator">></span><span class="ruby-keyword">true</span>)
|
||||
=<span class="ruby-operator">></span> <span class="ruby-identifier">raises</span> <span class="ruby-constant">FastImage</span><span class="ruby-operator">::</span><span class="ruby-constant">ImageFetchFailure</span>
|
||||
<span class="ruby-constant">FastImage</span>.<span class="ruby-identifier">size</span>(<span class="ruby-string">"http://stephensykes.com/favicon.ico"</span>, :<span class="ruby-identifier">raise_on_failure=</span><span class="ruby-operator">></span><span class="ruby-keyword">true</span>)
|
||||
=<span class="ruby-operator">></span> <span class="ruby-identifier">raises</span> <span class="ruby-constant">FastImage</span><span class="ruby-operator">::</span><span class="ruby-constant">UnknownImageType</span>
|
||||
<span class="ruby-constant">FastImage</span>.<span class="ruby-identifier">size</span>(<span class="ruby-string">"http://stephensykes.com/favicon.ico"</span>, :<span class="ruby-identifier">raise_on_failure=</span><span class="ruby-operator">></span><span class="ruby-keyword">true</span>, :<span class="ruby-identifier">timeout=</span><span class="ruby-operator">></span><span class="ruby-value">0.01</span>)
|
||||
=<span class="ruby-operator">></span> <span class="ruby-identifier">raises</span> <span class="ruby-constant">FastImage</span><span class="ruby-operator">::</span><span class="ruby-constant">ImageFetchFailure</span>
|
||||
<span class="ruby-constant">FastImage</span>.<span class="ruby-identifier">size</span>(<span class="ruby-string">"http://stephensykes.com/images/faulty.jpg"</span>, :<span class="ruby-identifier">raise_on_failure=</span><span class="ruby-operator">></span><span class="ruby-keyword">true</span>)
|
||||
=<span class="ruby-operator">></span> <span class="ruby-identifier">raises</span> <span class="ruby-constant">FastImage</span><span class="ruby-operator">::</span><span class="ruby-constant">SizeNotFound</span>
|
||||
</pre>
|
||||
|
||||
<h3 id="method-c-size-label-Supported+options">Supported options<span><a href="#method-c-size-label-Supported+options">¶</a> <a href="#documentation">↑</a></span></h3>
|
||||
<dl class="rdoc-list label-list"><dt>:timeout
|
||||
<dd>
|
||||
<p>Overrides the default timeout of 2 seconds. Applies both to reading from
|
||||
and opening the http connection.</p>
|
||||
</dd><dt>:raise_on_failure
|
||||
<dd>
|
||||
<p>If set to true causes an exception to be raised if the image size cannot be
|
||||
found for any reason.</p>
|
||||
</dd></dl>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="method-source-code" id="size-source">
|
||||
<pre><span class="ruby-comment"># File lib/fastimage.rb, line 111</span>
|
||||
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">size</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">options</span>={})
|
||||
<span class="ruby-identifier">new</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">size</span>
|
||||
<span class="ruby-keyword">end</span></pre>
|
||||
</div><!-- size-source -->
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</div><!-- size-method -->
|
||||
|
||||
|
||||
<div id="method-c-type" class="method-detail ">
|
||||
|
||||
<div class="method-heading">
|
||||
<span class="method-name">type</span><span
|
||||
class="method-args">(uri, options={})</span>
|
||||
|
||||
<span class="method-click-advice">click to toggle source</span>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="method-description">
|
||||
|
||||
<p>Returns an symbol indicating the image type fetched from a uri. It will
|
||||
return nil if the image could not be fetched, or if the image type was not
|
||||
recognised.</p>
|
||||
|
||||
<p>By default there is a timeout of 2 seconds for opening and reading from a
|
||||
remote server. This can be changed by passing a :timeout =>
|
||||
number_of_seconds in the options.</p>
|
||||
|
||||
<p>If you wish <a href="FastImage.html">FastImage</a> to raise if it cannot
|
||||
find the type of the image for any reason, then pass :raise_on_failure
|
||||
=> true in the options.</p>
|
||||
|
||||
<h3 id="method-c-type-label-Example">Example<span><a href="#method-c-type-label-Example">¶</a> <a href="#documentation">↑</a></span></h3>
|
||||
|
||||
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'fastimage'</span>
|
||||
|
||||
<span class="ruby-constant">FastImage</span>.<span class="ruby-identifier">type</span>(<span class="ruby-string">"http://stephensykes.com/images/ss.com_x.gif"</span>)
|
||||
=<span class="ruby-operator">></span> :<span class="ruby-identifier">gif</span>
|
||||
<span class="ruby-constant">FastImage</span>.<span class="ruby-identifier">type</span>(<span class="ruby-string">"http://stephensykes.com/images/pngimage"</span>)
|
||||
=<span class="ruby-operator">></span> :<span class="ruby-identifier">png</span>
|
||||
<span class="ruby-constant">FastImage</span>.<span class="ruby-identifier">type</span>(<span class="ruby-string">"http://farm4.static.flickr.com/3023/3047236863_9dce98b836.jpg"</span>)
|
||||
=<span class="ruby-operator">></span> :<span class="ruby-identifier">jpeg</span>
|
||||
<span class="ruby-constant">FastImage</span>.<span class="ruby-identifier">type</span>(<span class="ruby-string">"http://www-ece.rice.edu/~wakin/images/lena512.bmp"</span>)
|
||||
=<span class="ruby-operator">></span> :<span class="ruby-identifier">bmp</span>
|
||||
<span class="ruby-constant">FastImage</span>.<span class="ruby-identifier">type</span>(<span class="ruby-string">"test/fixtures/test.jpg"</span>)
|
||||
=<span class="ruby-operator">></span> :<span class="ruby-identifier">jpeg</span>
|
||||
<span class="ruby-constant">FastImage</span>.<span class="ruby-identifier">type</span>(<span class="ruby-string">"http://pennysmalls.com/does_not_exist"</span>)
|
||||
=<span class="ruby-operator">></span> <span class="ruby-keyword">nil</span>
|
||||
<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">"/some/local/file.gif"</span>, <span class="ruby-string">"r"</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">io</span><span class="ruby-operator">|</span> <span class="ruby-constant">FastImage</span>.<span class="ruby-identifier">type</span>(<span class="ruby-identifier">io</span>)}
|
||||
=<span class="ruby-operator">></span> :<span class="ruby-identifier">gif</span>
|
||||
<span class="ruby-constant">FastImage</span>.<span class="ruby-identifier">type</span>(<span class="ruby-string">"test/fixtures/test.tiff"</span>)
|
||||
=<span class="ruby-operator">></span> :<span class="ruby-identifier">tiff</span>
|
||||
<span class="ruby-constant">FastImage</span>.<span class="ruby-identifier">type</span>(<span class="ruby-string">"test/fixtures/test.psd"</span>)
|
||||
=<span class="ruby-operator">></span> :<span class="ruby-identifier">psd</span>
|
||||
</pre>
|
||||
|
||||
<h3 id="method-c-type-label-Supported+options">Supported options<span><a href="#method-c-type-label-Supported+options">¶</a> <a href="#documentation">↑</a></span></h3>
|
||||
<dl class="rdoc-list label-list"><dt>:timeout
|
||||
<dd>
|
||||
<p>Overrides the default timeout of 2 seconds. Applies both to reading from
|
||||
and opening the http connection.</p>
|
||||
</dd><dt>:raise_on_failure
|
||||
<dd>
|
||||
<p>If set to true causes an exception to be raised if the image type cannot be
|
||||
found for any reason.</p>
|
||||
</dd></dl>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="method-source-code" id="type-source">
|
||||
<pre><span class="ruby-comment"># File lib/fastimage.rb, line 153</span>
|
||||
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">type</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">options</span>={})
|
||||
<span class="ruby-identifier">new</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">options</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-value">:type_only=</span><span class="ruby-operator">></span><span class="ruby-keyword">true</span>)).<span class="ruby-identifier">type</span>
|
||||
<span class="ruby-keyword">end</span></pre>
|
||||
</div><!-- type-source -->
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</div><!-- type-method -->
|
||||
|
||||
|
||||
</section><!-- public-class-method-details -->
|
||||
|
||||
</section><!-- 5Buntitled-5D -->
|
||||
|
||||
</div><!-- documentation -->
|
||||
|
||||
|
||||
<footer id="validator-badges">
|
||||
<p><a href="http://validator.w3.org/check/referer">[Validate]</a>
|
||||
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 4.0.0.
|
||||
<p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
|
||||
</footer>
|
||||
|
@ -1,3 +0,0 @@
|
||||
Wed, 29 Jan 2014 22:20:31 +0200
|
||||
lib/fastimage.rb Wed, 29 Jan 2014 22:20:21 +0200
|
||||
lib/fastimage/fbr.rb Wed, 08 May 2013 16:45:51 +0300
|
Before Width: | Height: | Size: 733 B |
Before Width: | Height: | Size: 372 B |
Before Width: | Height: | Size: 452 B |
Before Width: | Height: | Size: 764 B |
Before Width: | Height: | Size: 774 B |
Before Width: | Height: | Size: 211 B |
Before Width: | Height: | Size: 207 B |
Before Width: | Height: | Size: 209 B |
Before Width: | Height: | Size: 626 B |
Before Width: | Height: | Size: 715 B |
Before Width: | Height: | Size: 659 B |
Before Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 207 B |
Before Width: | Height: | Size: 853 B |
Before Width: | Height: | Size: 621 B |
Before Width: | Height: | Size: 342 B |
Before Width: | Height: | Size: 309 B |
Before Width: | Height: | Size: 591 B |
Before Width: | Height: | Size: 592 B |
Before Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 613 B |
Before Width: | Height: | Size: 97 B |
Before Width: | Height: | Size: 610 B |
Before Width: | Height: | Size: 584 B |
Before Width: | Height: | Size: 692 B |
@ -1,71 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
|
||||
|
||||
<title>RDoc Documentation</title>
|
||||
|
||||
<link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
|
||||
|
||||
<script type="text/javascript">
|
||||
var rdoc_rel_prefix = "./";
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
|
||||
|
||||
|
||||
<body>
|
||||
<nav id="metadata">
|
||||
<nav id="home-section" class="section">
|
||||
<h3 class="section-header">
|
||||
<a href="./index.html">Home</a>
|
||||
<a href="./table_of_contents.html#classes">Classes</a>
|
||||
<a href="./table_of_contents.html#methods">Methods</a>
|
||||
</h3>
|
||||
</nav>
|
||||
|
||||
|
||||
<nav id="search-section" class="section project-section" class="initially-hidden">
|
||||
<form action="#" method="get" accept-charset="utf-8">
|
||||
<h3 class="section-header">
|
||||
<input type="text" name="search" placeholder="Search" id="search-field"
|
||||
title="Type to search, Up and Down to navigate, Enter to load">
|
||||
</h3>
|
||||
</form>
|
||||
|
||||
<ul id="search-results" class="initially-hidden"></ul>
|
||||
</nav>
|
||||
|
||||
|
||||
<div id="project-metadata">
|
||||
|
||||
<nav id="classindex-section" class="section project-section">
|
||||
<h3 class="section-header">Class and Module Index</h3>
|
||||
|
||||
<ul class="link-list">
|
||||
|
||||
<li><a href="./FastImage.html">FastImage</a>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div id="documentation" class="description">
|
||||
<p>This is the API documentation for RDoc Documentation.
|
||||
</div>
|
||||
|
||||
|
||||
<footer id="validator-badges">
|
||||
<p><a href="http://validator.w3.org/check/referer">[Validate]</a>
|
||||
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 4.0.0.
|
||||
<p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
|
||||
</footer>
|
||||
|
@ -1,155 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Darkfish Page Functions
|
||||
* $Id: darkfish.js 53 2009-01-07 02:52:03Z deveiant $
|
||||
*
|
||||
* Author: Michael Granger <mgranger@laika.com>
|
||||
*
|
||||
*/
|
||||
|
||||
/* Provide console simulation for firebug-less environments */
|
||||
if (!("console" in window) || !("firebug" in console)) {
|
||||
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
|
||||
"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
|
||||
|
||||
window.console = {};
|
||||
for (var i = 0; i < names.length; ++i)
|
||||
window.console[names[i]] = function() {};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Unwrap the first element that matches the given @expr@ from the targets and return them.
|
||||
*/
|
||||
$.fn.unwrap = function( expr ) {
|
||||
return this.each( function() {
|
||||
$(this).parents( expr ).eq( 0 ).after( this ).remove();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
function showSource( e ) {
|
||||
var target = e.target;
|
||||
var codeSections = $(target).
|
||||
parents('.method-detail').
|
||||
find('.method-source-code');
|
||||
|
||||
$(target).
|
||||
parents('.method-detail').
|
||||
find('.method-source-code').
|
||||
slideToggle();
|
||||
};
|
||||
|
||||
function hookSourceViews() {
|
||||
$('.method-heading').click( showSource );
|
||||
};
|
||||
|
||||
function toggleDebuggingSection() {
|
||||
$('.debugging-section').slideToggle();
|
||||
};
|
||||
|
||||
function hookDebuggingToggle() {
|
||||
$('#debugging-toggle img').click( toggleDebuggingSection );
|
||||
};
|
||||
|
||||
function hookTableOfContentsToggle() {
|
||||
$('.indexpage li .toc-toggle').each( function() {
|
||||
$(this).click( function() {
|
||||
$(this).toggleClass('open');
|
||||
});
|
||||
|
||||
var section = $(this).next();
|
||||
|
||||
$(this).click( function() {
|
||||
section.slideToggle();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function hookSearch() {
|
||||
var input = $('#search-field').eq(0);
|
||||
var result = $('#search-results').eq(0);
|
||||
$(result).show();
|
||||
|
||||
var search_section = $('#search-section').get(0);
|
||||
$(search_section).show();
|
||||
|
||||
var search = new Search(search_data, input, result);
|
||||
|
||||
search.renderItem = function(result) {
|
||||
var li = document.createElement('li');
|
||||
var html = '';
|
||||
|
||||
// TODO add relative path to <script> per-page
|
||||
html += '<p class="search-match"><a href="' + rdoc_rel_prefix + result.path + '">' + this.hlt(result.title);
|
||||
if (result.params)
|
||||
html += '<span class="params">' + result.params + '</span>';
|
||||
html += '</a>';
|
||||
|
||||
|
||||
if (result.namespace)
|
||||
html += '<p class="search-namespace">' + this.hlt(result.namespace);
|
||||
|
||||
if (result.snippet)
|
||||
html += '<div class="search-snippet">' + result.snippet + '</div>';
|
||||
|
||||
li.innerHTML = html;
|
||||
|
||||
return li;
|
||||
}
|
||||
|
||||
search.select = function(result) {
|
||||
var result_element = result.get(0);
|
||||
window.location.href = result_element.firstChild.firstChild.href;
|
||||
}
|
||||
|
||||
search.scrollIntoView = search.scrollInWindow;
|
||||
};
|
||||
|
||||
function highlightTarget( anchor ) {
|
||||
console.debug( "Highlighting target '%s'.", anchor );
|
||||
|
||||
$("a[name]").each( function() {
|
||||
if ( $(this).attr("name") == anchor ) {
|
||||
if ( !$(this).parent().parent().hasClass('target-section') ) {
|
||||
console.debug( "Wrapping the target-section" );
|
||||
$('div.method-detail').unwrap( 'div.target-section' );
|
||||
$(this).parent().wrap( '<div class="target-section"></div>' );
|
||||
} else {
|
||||
console.debug( "Already wrapped." );
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function highlightLocationTarget() {
|
||||
console.debug( "Location hash: %s", window.location.hash );
|
||||
if ( ! window.location.hash || window.location.hash.length == 0 ) return;
|
||||
|
||||
var anchor = window.location.hash.substring(1);
|
||||
console.debug( "Found anchor: %s; matching %s", anchor, "a[name=" + anchor + "]" );
|
||||
|
||||
highlightTarget( anchor );
|
||||
};
|
||||
|
||||
function highlightClickTarget( event ) {
|
||||
console.debug( "Highlighting click target for event %o", event.target );
|
||||
try {
|
||||
var anchor = $(event.target).attr( 'href' ).substring(1);
|
||||
console.debug( "Found target anchor: %s", anchor );
|
||||
highlightTarget( anchor );
|
||||
} catch ( err ) {
|
||||
console.error( "Exception while highlighting: %o", err );
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
$(document).ready( function() {
|
||||
hookSourceViews();
|
||||
hookDebuggingToggle();
|
||||
hookSearch();
|
||||
highlightLocationTarget();
|
||||
hookTableOfContentsToggle();
|
||||
|
||||
$('ul.link-list a').bind( "click", highlightClickTarget );
|
||||
});
|
18
rdoc/js/jquery.js
vendored
@ -1,142 +0,0 @@
|
||||
/*
|
||||
* Navigation allows movement using the arrow keys through the search results.
|
||||
*
|
||||
* When using this library you will need to set scrollIntoView to the
|
||||
* appropriate function for your layout. Use scrollInWindow if the container
|
||||
* is not scrollable and scrollInElement if the container is a separate
|
||||
* scrolling region.
|
||||
*/
|
||||
Navigation = new function() {
|
||||
this.initNavigation = function() {
|
||||
var _this = this;
|
||||
|
||||
$(document).keydown(function(e) {
|
||||
_this.onkeydown(e);
|
||||
}).keyup(function(e) {
|
||||
_this.onkeyup(e);
|
||||
});
|
||||
|
||||
this.navigationActive = true;
|
||||
}
|
||||
|
||||
this.setNavigationActive = function(state) {
|
||||
this.navigationActive = state;
|
||||
this.clearMoveTimeout();
|
||||
}
|
||||
|
||||
this.onkeyup = function(e) {
|
||||
if (!this.navigationActive) return;
|
||||
|
||||
switch(e.keyCode) {
|
||||
case 37: //Event.KEY_LEFT:
|
||||
case 38: //Event.KEY_UP:
|
||||
case 39: //Event.KEY_RIGHT:
|
||||
case 40: //Event.KEY_DOWN:
|
||||
this.clearMoveTimeout();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.onkeydown = function(e) {
|
||||
if (!this.navigationActive) return;
|
||||
switch(e.keyCode) {
|
||||
case 37: //Event.KEY_LEFT:
|
||||
if (this.moveLeft()) e.preventDefault();
|
||||
break;
|
||||
case 38: //Event.KEY_UP:
|
||||
if (e.keyCode == 38 || e.ctrlKey) {
|
||||
if (this.moveUp()) e.preventDefault();
|
||||
this.startMoveTimeout(false);
|
||||
}
|
||||
break;
|
||||
case 39: //Event.KEY_RIGHT:
|
||||
if (this.moveRight()) e.preventDefault();
|
||||
break;
|
||||
case 40: //Event.KEY_DOWN:
|
||||
if (e.keyCode == 40 || e.ctrlKey) {
|
||||
if (this.moveDown()) e.preventDefault();
|
||||
this.startMoveTimeout(true);
|
||||
}
|
||||
break;
|
||||
case 13: //Event.KEY_RETURN:
|
||||
if (this.$current)
|
||||
e.preventDefault();
|
||||
this.select(this.$current);
|
||||
break;
|
||||
}
|
||||
if (e.ctrlKey && e.shiftKey) this.select(this.$current);
|
||||
}
|
||||
|
||||
this.clearMoveTimeout = function() {
|
||||
clearTimeout(this.moveTimeout);
|
||||
this.moveTimeout = null;
|
||||
}
|
||||
|
||||
this.startMoveTimeout = function(isDown) {
|
||||
if (!$.browser.mozilla && !$.browser.opera) return;
|
||||
if (this.moveTimeout) this.clearMoveTimeout();
|
||||
var _this = this;
|
||||
|
||||
var go = function() {
|
||||
if (!_this.moveTimeout) return;
|
||||
_this[isDown ? 'moveDown' : 'moveUp']();
|
||||
_this.moveTimout = setTimeout(go, 100);
|
||||
}
|
||||
this.moveTimeout = setTimeout(go, 200);
|
||||
}
|
||||
|
||||
this.moveRight = function() {
|
||||
}
|
||||
|
||||
this.moveLeft = function() {
|
||||
}
|
||||
|
||||
this.move = function(isDown) {
|
||||
}
|
||||
|
||||
this.moveUp = function() {
|
||||
return this.move(false);
|
||||
}
|
||||
|
||||
this.moveDown = function() {
|
||||
return this.move(true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Scrolls to the given element in the scrollable element view.
|
||||
*/
|
||||
this.scrollInElement = function(element, view) {
|
||||
var offset, viewHeight, viewScroll, height;
|
||||
offset = element.offsetTop;
|
||||
height = element.offsetHeight;
|
||||
viewHeight = view.offsetHeight;
|
||||
viewScroll = view.scrollTop;
|
||||
|
||||
if (offset - viewScroll + height > viewHeight) {
|
||||
view.scrollTop = offset - viewHeight + height;
|
||||
}
|
||||
if (offset < viewScroll) {
|
||||
view.scrollTop = offset;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Scrolls to the given element in the window. The second argument is
|
||||
* ignored
|
||||
*/
|
||||
this.scrollInWindow = function(element, ignored) {
|
||||
var offset, viewHeight, viewScroll, height;
|
||||
offset = element.offsetTop;
|
||||
height = element.offsetHeight;
|
||||
viewHeight = window.innerHeight;
|
||||
viewScroll = window.scrollY;
|
||||
|
||||
if (offset - viewScroll + height > viewHeight) {
|
||||
window.scrollTo(window.scrollX, offset - viewHeight + height);
|
||||
}
|
||||
if (offset < viewScroll) {
|
||||
window.scrollTo(window.scrollX, offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,94 +0,0 @@
|
||||
Search = function(data, input, result) {
|
||||
this.data = data;
|
||||
this.$input = $(input);
|
||||
this.$result = $(result);
|
||||
|
||||
this.$current = null;
|
||||
this.$view = this.$result.parent();
|
||||
this.searcher = new Searcher(data.index);
|
||||
this.init();
|
||||
}
|
||||
|
||||
Search.prototype = $.extend({}, Navigation, new function() {
|
||||
var suid = 1;
|
||||
|
||||
this.init = function() {
|
||||
var _this = this;
|
||||
var observer = function() {
|
||||
_this.search(_this.$input[0].value);
|
||||
};
|
||||
this.$input.keyup(observer);
|
||||
this.$input.click(observer); // mac's clear field
|
||||
|
||||
this.searcher.ready(function(results, isLast) {
|
||||
_this.addResults(results, isLast);
|
||||
})
|
||||
|
||||
this.initNavigation();
|
||||
this.setNavigationActive(false);
|
||||
}
|
||||
|
||||
this.search = function(value, selectFirstMatch) {
|
||||
value = jQuery.trim(value).toLowerCase();
|
||||
if (value) {
|
||||
this.setNavigationActive(true);
|
||||
} else {
|
||||
this.setNavigationActive(false);
|
||||
}
|
||||
|
||||
if (value == '') {
|
||||
this.lastQuery = value;
|
||||
this.$result.empty();
|
||||
this.setNavigationActive(false);
|
||||
} else if (value != this.lastQuery) {
|
||||
this.lastQuery = value;
|
||||
this.firstRun = true;
|
||||
this.searcher.find(value);
|
||||
}
|
||||
}
|
||||
|
||||
this.addResults = function(results, isLast) {
|
||||
var target = this.$result.get(0);
|
||||
if (this.firstRun && (results.length > 0 || isLast)) {
|
||||
this.$current = null;
|
||||
this.$result.empty();
|
||||
}
|
||||
|
||||
for (var i=0, l = results.length; i < l; i++) {
|
||||
target.appendChild(this.renderItem.call(this, results[i]));
|
||||
};
|
||||
|
||||
if (this.firstRun && results.length > 0) {
|
||||
this.firstRun = false;
|
||||
this.$current = $(target.firstChild);
|
||||
this.$current.addClass('current');
|
||||
}
|
||||
if (jQuery.browser.msie) this.$element[0].className += '';
|
||||
}
|
||||
|
||||
this.move = function(isDown) {
|
||||
if (!this.$current) return;
|
||||
var $next = this.$current[isDown ? 'next' : 'prev']();
|
||||
if ($next.length) {
|
||||
this.$current.removeClass('current');
|
||||
$next.addClass('current');
|
||||
this.scrollIntoView($next[0], this.$view[0]);
|
||||
this.$current = $next;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
this.hlt = function(html) {
|
||||
return this.escapeHTML(html).
|
||||
replace(/\u0001/g, '<em>').
|
||||
replace(/\u0002/g, '</em>');
|
||||
}
|
||||
|
||||
this.escapeHTML = function(html) {
|
||||
return html.replace(/[&<>]/g, function(c) {
|
||||
return '&#' + c.charCodeAt(0) + ';';
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -1 +0,0 @@
|
||||
var search_data = {"index":{"searchIndex":["fastimage","new()","size()","type()"],"longSearchIndex":["fastimage","fastimage::new()","fastimage::size()","fastimage::type()"],"info":[["FastImage","","FastImage.html","",""],["new","FastImage","FastImage.html#method-c-new","(uri, options={})",""],["size","FastImage","FastImage.html#method-c-size","(uri, options={})","<p>Returns an array containing the width and height of the image. It will\nreturn nil if the image could …\n"],["type","FastImage","FastImage.html#method-c-type","(uri, options={})","<p>Returns an symbol indicating the image type fetched from a uri. It will\nreturn nil if the image could …\n"]]}}
|
@ -1,228 +0,0 @@
|
||||
Searcher = function(data) {
|
||||
this.data = data;
|
||||
this.handlers = [];
|
||||
}
|
||||
|
||||
Searcher.prototype = new function() {
|
||||
// search is performed in chunks of 1000 for non-blocking user input
|
||||
var CHUNK_SIZE = 1000;
|
||||
// do not try to find more than 100 results
|
||||
var MAX_RESULTS = 100;
|
||||
var huid = 1;
|
||||
var suid = 1;
|
||||
var runs = 0;
|
||||
|
||||
this.find = function(query) {
|
||||
var queries = splitQuery(query);
|
||||
var regexps = buildRegexps(queries);
|
||||
var highlighters = buildHilighters(queries);
|
||||
var state = { from: 0, pass: 0, limit: MAX_RESULTS, n: suid++};
|
||||
var _this = this;
|
||||
|
||||
this.currentSuid = state.n;
|
||||
|
||||
if (!query) return;
|
||||
|
||||
var run = function() {
|
||||
// stop current search thread if new search started
|
||||
if (state.n != _this.currentSuid) return;
|
||||
|
||||
var results =
|
||||
performSearch(_this.data, regexps, queries, highlighters, state);
|
||||
var hasMore = (state.limit > 0 && state.pass < 4);
|
||||
|
||||
triggerResults.call(_this, results, !hasMore);
|
||||
if (hasMore) {
|
||||
setTimeout(run, 2);
|
||||
}
|
||||
runs++;
|
||||
};
|
||||
runs = 0;
|
||||
|
||||
// start search thread
|
||||
run();
|
||||
}
|
||||
|
||||
/* ----- Events ------ */
|
||||
this.ready = function(fn) {
|
||||
fn.huid = huid;
|
||||
this.handlers.push(fn);
|
||||
}
|
||||
|
||||
/* ----- Utilities ------ */
|
||||
function splitQuery(query) {
|
||||
return jQuery.grep(query.split(/(\s+|::?|\(\)?)/), function(string) {
|
||||
return string.match(/\S/)
|
||||
});
|
||||
}
|
||||
|
||||
function buildRegexps(queries) {
|
||||
return jQuery.map(queries, function(query) {
|
||||
return new RegExp(query.replace(/(.)/g, '([$1])([^$1]*?)'), 'i')
|
||||
});
|
||||
}
|
||||
|
||||
function buildHilighters(queries) {
|
||||
return jQuery.map(queries, function(query) {
|
||||
return jQuery.map(query.split(''), function(l, i) {
|
||||
return '\u0001$' + (i*2+1) + '\u0002$' + (i*2+2);
|
||||
}).join('');
|
||||
});
|
||||
}
|
||||
|
||||
// function longMatchRegexp(index, longIndex, regexps) {
|
||||
// for (var i = regexps.length - 1; i >= 0; i--){
|
||||
// if (!index.match(regexps[i]) && !longIndex.match(regexps[i])) return false;
|
||||
// };
|
||||
// return true;
|
||||
// }
|
||||
|
||||
|
||||
/* ----- Mathchers ------ */
|
||||
|
||||
/*
|
||||
* This record matches if the index starts with queries[0] and the record
|
||||
* matches all of the regexps
|
||||
*/
|
||||
function matchPassBeginning(index, longIndex, queries, regexps) {
|
||||
if (index.indexOf(queries[0]) != 0) return false;
|
||||
for (var i=1, l = regexps.length; i < l; i++) {
|
||||
if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
|
||||
return false;
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* This record matches if the longIndex starts with queries[0] and the
|
||||
* longIndex matches all of the regexps
|
||||
*/
|
||||
function matchPassLongIndex(index, longIndex, queries, regexps) {
|
||||
if (longIndex.indexOf(queries[0]) != 0) return false;
|
||||
for (var i=1, l = regexps.length; i < l; i++) {
|
||||
if (!longIndex.match(regexps[i]))
|
||||
return false;
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* This record matches if the index contains queries[0] and the record
|
||||
* matches all of the regexps
|
||||
*/
|
||||
function matchPassContains(index, longIndex, queries, regexps) {
|
||||
if (index.indexOf(queries[0]) == -1) return false;
|
||||
for (var i=1, l = regexps.length; i < l; i++) {
|
||||
if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
|
||||
return false;
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* This record matches if regexps[0] matches the index and the record
|
||||
* matches all of the regexps
|
||||
*/
|
||||
function matchPassRegexp(index, longIndex, queries, regexps) {
|
||||
if (!index.match(regexps[0])) return false;
|
||||
for (var i=1, l = regexps.length; i < l; i++) {
|
||||
if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
|
||||
return false;
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* ----- Highlighters ------ */
|
||||
function highlightRegexp(info, queries, regexps, highlighters) {
|
||||
var result = createResult(info);
|
||||
for (var i=0, l = regexps.length; i < l; i++) {
|
||||
result.title = result.title.replace(regexps[i], highlighters[i]);
|
||||
result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
function hltSubstring(string, pos, length) {
|
||||
return string.substring(0, pos) + '\u0001' + string.substring(pos, pos + length) + '\u0002' + string.substring(pos + length);
|
||||
}
|
||||
|
||||
function highlightQuery(info, queries, regexps, highlighters) {
|
||||
var result = createResult(info);
|
||||
var pos = 0;
|
||||
var lcTitle = result.title.toLowerCase();
|
||||
|
||||
pos = lcTitle.indexOf(queries[0]);
|
||||
if (pos != -1) {
|
||||
result.title = hltSubstring(result.title, pos, queries[0].length);
|
||||
}
|
||||
|
||||
result.namespace = result.namespace.replace(regexps[0], highlighters[0]);
|
||||
for (var i=1, l = regexps.length; i < l; i++) {
|
||||
result.title = result.title.replace(regexps[i], highlighters[i]);
|
||||
result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
function createResult(info) {
|
||||
var result = {};
|
||||
result.title = info[0];
|
||||
result.namespace = info[1];
|
||||
result.path = info[2];
|
||||
result.params = info[3];
|
||||
result.snippet = info[4];
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ----- Searching ------ */
|
||||
function performSearch(data, regexps, queries, highlighters, state) {
|
||||
var searchIndex = data.searchIndex;
|
||||
var longSearchIndex = data.longSearchIndex;
|
||||
var info = data.info;
|
||||
var result = [];
|
||||
var i = state.from;
|
||||
var l = searchIndex.length;
|
||||
var togo = CHUNK_SIZE;
|
||||
var matchFunc, hltFunc;
|
||||
|
||||
while (state.pass < 4 && state.limit > 0 && togo > 0) {
|
||||
if (state.pass == 0) {
|
||||
matchFunc = matchPassBeginning;
|
||||
hltFunc = highlightQuery;
|
||||
} else if (state.pass == 1) {
|
||||
matchFunc = matchPassLongIndex;
|
||||
hltFunc = highlightQuery;
|
||||
} else if (state.pass == 2) {
|
||||
matchFunc = matchPassContains;
|
||||
hltFunc = highlightQuery;
|
||||
} else if (state.pass == 3) {
|
||||
matchFunc = matchPassRegexp;
|
||||
hltFunc = highlightRegexp;
|
||||
}
|
||||
|
||||
for (; togo > 0 && i < l && state.limit > 0; i++, togo--) {
|
||||
if (info[i].n == state.n) continue;
|
||||
if (matchFunc(searchIndex[i], longSearchIndex[i], queries, regexps)) {
|
||||
info[i].n = state.n;
|
||||
result.push(hltFunc(info[i], queries, regexps, highlighters));
|
||||
state.limit--;
|
||||
}
|
||||
};
|
||||
if (searchIndex.length <= i) {
|
||||
state.pass++;
|
||||
i = state.from = 0;
|
||||
} else {
|
||||
state.from = i;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function triggerResults(results, isLast) {
|
||||
jQuery.each(this.handlers, function(i, fn) {
|
||||
fn.call(this, results, isLast)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
595
rdoc/rdoc.css
@ -1,595 +0,0 @@
|
||||
/*
|
||||
* "Darkfish" Rdoc CSS
|
||||
* $Id: rdoc.css 54 2009-01-27 01:09:48Z deveiant $
|
||||
*
|
||||
* Author: Michael Granger <ged@FaerieMUD.org>
|
||||
*
|
||||
*/
|
||||
|
||||
/* vim: ft=css et sw=2 ts=2 sts=2 */
|
||||
/* Base Green is: #6C8C22 */
|
||||
|
||||
* { padding: 0; margin: 0; }
|
||||
|
||||
body {
|
||||
background: #efefef;
|
||||
font: 14px "Helvetica Neue", Helvetica, Tahoma, sans-serif;
|
||||
margin-left: 40px;
|
||||
}
|
||||
body.file-popup {
|
||||
font-size: 90%;
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 300%;
|
||||
text-shadow: rgba(135,145,135,0.65) 2px 2px 3px;
|
||||
color: #6C8C22;
|
||||
}
|
||||
h2,h3,h4 { margin-top: 1.5em; }
|
||||
|
||||
h1 span,
|
||||
h2 span,
|
||||
h3 span,
|
||||
h4 span,
|
||||
h5 span,
|
||||
h6 span {
|
||||
display: none;
|
||||
padding-left: 1em;
|
||||
font-size: 50%;
|
||||
vertical-align: super;
|
||||
}
|
||||
|
||||
h1:hover span,
|
||||
h2:hover span,
|
||||
h3:hover span,
|
||||
h4:hover span,
|
||||
h5:hover span,
|
||||
h6:hover span {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
:link,
|
||||
:visited {
|
||||
color: #6C8C22;
|
||||
text-decoration: none;
|
||||
}
|
||||
:link:hover,
|
||||
:visited:hover {
|
||||
border-bottom: 1px dotted #6C8C22;
|
||||
}
|
||||
|
||||
pre {
|
||||
background: #ddd;
|
||||
padding: 0.5em 0;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
background: #ddd;
|
||||
margin: 1em;
|
||||
padding: 0.25em;
|
||||
}
|
||||
|
||||
blockquote > :first-child {
|
||||
margin-top: 0 !important;
|
||||
}
|
||||
|
||||
/* @group Generic Classes */
|
||||
|
||||
.initially-hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#search-field {
|
||||
width: 98%;
|
||||
background: #eee;
|
||||
border: none;
|
||||
height: 1.5em;
|
||||
-webkit-border-radius: 4px;
|
||||
}
|
||||
#search-field:focus {
|
||||
background: #f1edba;
|
||||
}
|
||||
#search-field:-moz-placeholder,
|
||||
#search-field::-webkit-input-placeholder {
|
||||
font-weight: bold;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.missing-docs {
|
||||
font-size: 120%;
|
||||
background: white url(images/wrench_orange.png) no-repeat 4px center;
|
||||
color: #ccc;
|
||||
line-height: 2em;
|
||||
border: 1px solid #d00;
|
||||
opacity: 1;
|
||||
padding-left: 20px;
|
||||
text-indent: 24px;
|
||||
letter-spacing: 3px;
|
||||
font-weight: bold;
|
||||
-webkit-border-radius: 5px;
|
||||
-moz-border-radius: 5px;
|
||||
}
|
||||
|
||||
.target-section {
|
||||
border: 2px solid #dcce90;
|
||||
border-left-width: 8px;
|
||||
padding: 0 1em;
|
||||
background: #fff3c2;
|
||||
}
|
||||
|
||||
/* @end */
|
||||
|
||||
/* @group Index Page, Standalone file pages */
|
||||
.indexpage ul {
|
||||
line-height: 160%;
|
||||
list-style: none;
|
||||
}
|
||||
.indexpage ul :link,
|
||||
.indexpage ul :visited {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.indexpage li {
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
.indexpage ul > li {
|
||||
background: url(images/bullet_black.png) no-repeat left 4px;
|
||||
}
|
||||
.indexpage li.method {
|
||||
background: url(images/plugin.png) no-repeat left 4px;
|
||||
}
|
||||
.indexpage li.module {
|
||||
background: url(images/package.png) no-repeat left 4px;
|
||||
}
|
||||
.indexpage li.class {
|
||||
background: url(images/ruby.png) no-repeat left 4px;
|
||||
}
|
||||
.indexpage li.file {
|
||||
background: url(images/page_white_text.png) no-repeat left 4px;
|
||||
}
|
||||
.indexpage li li {
|
||||
background: url(images/tag_blue.png) no-repeat left 4px;
|
||||
}
|
||||
.indexpage li .toc-toggle {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
background: url(images/add.png) no-repeat;
|
||||
}
|
||||
|
||||
.indexpage li .toc-toggle.open {
|
||||
background: url(images/delete.png) no-repeat;
|
||||
}
|
||||
|
||||
/* @end */
|
||||
|
||||
/* @group Top-Level Structure */
|
||||
|
||||
#metadata {
|
||||
float: left;
|
||||
width: 260px;
|
||||
}
|
||||
|
||||
#documentation {
|
||||
margin: 2em 1em 5em 300px;
|
||||
min-width: 340px;
|
||||
}
|
||||
|
||||
#validator-badges {
|
||||
clear: both;
|
||||
margin: 1em 1em 2em;
|
||||
font-size: smaller;
|
||||
}
|
||||
|
||||
/* @end */
|
||||
|
||||
/* @group Metadata Section */
|
||||
#metadata .section {
|
||||
background-color: #dedede;
|
||||
-moz-border-radius: 5px;
|
||||
-webkit-border-radius: 5px;
|
||||
border: 1px solid #aaa;
|
||||
margin: 0 8px 8px;
|
||||
font-size: 90%;
|
||||
overflow: hidden;
|
||||
}
|
||||
#metadata h3.section-header {
|
||||
margin: 0;
|
||||
padding: 2px 8px;
|
||||
background: #ccc;
|
||||
color: #666;
|
||||
-moz-border-radius-topleft: 4px;
|
||||
-moz-border-radius-topright: 4px;
|
||||
-webkit-border-top-left-radius: 4px;
|
||||
-webkit-border-top-right-radius: 4px;
|
||||
border-bottom: 1px solid #aaa;
|
||||
}
|
||||
#metadata #home-section h3.section-header {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
#metadata ul,
|
||||
#metadata dl,
|
||||
#metadata p {
|
||||
padding: 8px;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
#file-metadata {
|
||||
margin-top: 2em;
|
||||
}
|
||||
|
||||
#file-metadata ul {
|
||||
padding-left: 28px;
|
||||
list-style-image: url(images/page_green.png);
|
||||
}
|
||||
|
||||
#table-of-contents {
|
||||
margin-top: 2em;
|
||||
}
|
||||
|
||||
#table-of-contents ul {
|
||||
padding-left: 28px;
|
||||
list-style-image: url(images/tag_blue.png);
|
||||
}
|
||||
|
||||
dl.svninfo {
|
||||
color: #666;
|
||||
margin: 0;
|
||||
}
|
||||
dl.svninfo dt {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
ul.link-list li {
|
||||
white-space: nowrap;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
ul.link-list .type {
|
||||
font-size: 8px;
|
||||
text-transform: uppercase;
|
||||
color: white;
|
||||
background: #969696;
|
||||
padding: 2px 4px;
|
||||
-webkit-border-radius: 5px;
|
||||
}
|
||||
|
||||
.calls-super {
|
||||
background: url(images/arrow_up.png) no-repeat right center;
|
||||
}
|
||||
|
||||
/* @end */
|
||||
|
||||
/* @group Class Metadata Section */
|
||||
#class-metadata {
|
||||
margin-top: 2em;
|
||||
}
|
||||
/* @end */
|
||||
|
||||
/* @group Project Metadata Section */
|
||||
#project-metadata {
|
||||
margin-top: 2em;
|
||||
}
|
||||
|
||||
#project-metadata .section {
|
||||
border: 1px solid #aaa;
|
||||
}
|
||||
#project-metadata h3.section-header {
|
||||
border-bottom: 1px solid #aaa;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#project-metadata form {
|
||||
color: #777;
|
||||
background: #ccc;
|
||||
}
|
||||
|
||||
/* @end */
|
||||
|
||||
/* @group Documentation Section */
|
||||
.description {
|
||||
font-size: 100%;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.description p {
|
||||
margin: 1em 0.4em;
|
||||
}
|
||||
|
||||
.description li p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.description ol,
|
||||
.description ul {
|
||||
margin-left: 1.5em;
|
||||
}
|
||||
.description ol li,
|
||||
.description ul li {
|
||||
line-height: 1.4em;
|
||||
}
|
||||
|
||||
.note-list {
|
||||
margin: 8px 0;
|
||||
}
|
||||
|
||||
.label-list {
|
||||
margin: 8px 1.5em;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
.description .label-list {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.note-list dt {
|
||||
font-weight: bold;
|
||||
}
|
||||
.note-list dd {
|
||||
padding: 0 12px;
|
||||
}
|
||||
|
||||
.label-list dt {
|
||||
padding: 2px 4px;
|
||||
font-weight: bold;
|
||||
background: #ddd;
|
||||
}
|
||||
.label-list dd {
|
||||
padding: 2px 12px;
|
||||
}
|
||||
.label-list dd + dt,
|
||||
.note-list dd + dt {
|
||||
margin-top: 0.7em;
|
||||
}
|
||||
|
||||
#documentation .section {
|
||||
font-size: 90%;
|
||||
}
|
||||
|
||||
#documentation h2.section-header {
|
||||
margin-top: 1em;
|
||||
padding: 0.25em 0.5em;
|
||||
background: #ccc;
|
||||
color: #333;
|
||||
font-size: 175%;
|
||||
border: 1px solid #bbb;
|
||||
-moz-border-radius: 3px;
|
||||
-webkit-border-radius: 3px;
|
||||
}
|
||||
|
||||
.documentation-section-title {
|
||||
position: relative;
|
||||
}
|
||||
.documentation-section-title .section-click-top {
|
||||
position: absolute;
|
||||
top: 6px;
|
||||
right: 12px;
|
||||
font-size: 10px;
|
||||
color: #9b9877;
|
||||
visibility: hidden;
|
||||
padding-right: 0.5px;
|
||||
}
|
||||
|
||||
.documentation-section-title:hover .section-click-top {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
#documentation h3.section-header {
|
||||
margin-top: 1em;
|
||||
padding: 0.25em 0.5em;
|
||||
background-color: #dedede;
|
||||
color: #333;
|
||||
font-size: 150%;
|
||||
border: 1px solid #bbb;
|
||||
-moz-border-radius: 3px;
|
||||
-webkit-border-radius: 3px;
|
||||
}
|
||||
|
||||
#constants-list > dl,
|
||||
#attributes-list > dl {
|
||||
margin: 1em 0 2em;
|
||||
border: 0;
|
||||
}
|
||||
#constants-list > dl dt,
|
||||
#attributes-list > dl dt {
|
||||
padding-left: 0;
|
||||
font-weight: bold;
|
||||
font-family: Monaco, "Andale Mono";
|
||||
background: inherit;
|
||||
}
|
||||
#constants-list > dl dt a,
|
||||
#attributes-list > dl dt a {
|
||||
color: inherit;
|
||||
}
|
||||
#constants-list > dl dd,
|
||||
#attributes-list > dl dd {
|
||||
margin: 0 0 1em 0;
|
||||
padding: 0;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.documentation-section h2 {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.documentation-section h2 a {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 10px;
|
||||
font-size: 12px;
|
||||
color: #9b9877;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.documentation-section h2:hover a {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
/* @group Method Details */
|
||||
|
||||
#documentation .method-source-code {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#documentation .method-description .method-calls-super {
|
||||
color: #333;
|
||||
font-weight: bolder;
|
||||
}
|
||||
|
||||
#documentation .method-detail {
|
||||
margin: 0.5em 0;
|
||||
padding: 0.5em 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
#documentation .method-detail:hover {
|
||||
background-color: #f1edba;
|
||||
}
|
||||
#documentation .method-heading {
|
||||
position: relative;
|
||||
padding: 2px 4px 0 20px;
|
||||
font-size: 125%;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
background: url(images/brick.png) no-repeat left bottom;
|
||||
}
|
||||
#documentation .method-heading :link,
|
||||
#documentation .method-heading :visited {
|
||||
color: inherit;
|
||||
}
|
||||
#documentation .method-click-advice {
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
right: 5px;
|
||||
font-size: 10px;
|
||||
color: #9b9877;
|
||||
visibility: hidden;
|
||||
padding-right: 20px;
|
||||
line-height: 20px;
|
||||
background: url(images/zoom.png) no-repeat right top;
|
||||
}
|
||||
#documentation .method-heading:hover .method-click-advice {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
#documentation .method-alias .method-heading {
|
||||
color: #666;
|
||||
background: url(images/brick_link.png) no-repeat left bottom;
|
||||
}
|
||||
|
||||
#documentation .method-description,
|
||||
#documentation .aliases {
|
||||
margin: 0 20px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
#documentation .method-description p,
|
||||
#documentation .aliases p {
|
||||
line-height: 1.2em;
|
||||
}
|
||||
|
||||
#documentation .aliases {
|
||||
padding-top: 4px;
|
||||
font-style: italic;
|
||||
cursor: default;
|
||||
}
|
||||
#documentation .method-description p {
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
#documentation .method-description ul {
|
||||
margin-left: 1.5em;
|
||||
}
|
||||
pre {
|
||||
margin: 0.5em 0;
|
||||
}
|
||||
|
||||
#documentation .attribute-method-heading {
|
||||
background: url(images/tag_green.png) no-repeat left bottom;
|
||||
}
|
||||
#documentation #attribute-method-details .method-detail:hover {
|
||||
background-color: transparent;
|
||||
cursor: default;
|
||||
}
|
||||
#documentation .attribute-access-type {
|
||||
font-size: 60%;
|
||||
text-transform: uppercase;
|
||||
vertical-align: super;
|
||||
padding: 0 2px;
|
||||
}
|
||||
/* @end */
|
||||
|
||||
/* @end */
|
||||
|
||||
/* @group Source Code */
|
||||
|
||||
pre {
|
||||
overflow: auto;
|
||||
background: #262626;
|
||||
color: white;
|
||||
border: 1px dashed #999;
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
.description pre {
|
||||
margin: 0 0.4em;
|
||||
}
|
||||
|
||||
.ruby-constant { color: #7fffd4; background: transparent; }
|
||||
.ruby-keyword { color: #00ffff; background: transparent; }
|
||||
.ruby-ivar { color: #eedd82; background: transparent; }
|
||||
.ruby-operator { color: #00ffee; background: transparent; }
|
||||
.ruby-identifier { color: #ffdead; background: transparent; }
|
||||
.ruby-node { color: #ffa07a; background: transparent; }
|
||||
.ruby-comment { color: #dc0000; font-weight: bold; background: transparent; }
|
||||
.ruby-regexp { color: #ffa07a; background: transparent; }
|
||||
.ruby-value { color: #7fffd4; background: transparent; }
|
||||
|
||||
/* @end */
|
||||
|
||||
|
||||
/* @group search results */
|
||||
#search-results h1 {
|
||||
font-size: 1em;
|
||||
font-weight: normal;
|
||||
text-shadow: none;
|
||||
}
|
||||
|
||||
#search-results .current {
|
||||
background: #ccc;
|
||||
border-bottom: 1px solid transparent;
|
||||
}
|
||||
|
||||
#search-results li {
|
||||
list-style: none;
|
||||
border-bottom: 1px solid #aaa;
|
||||
-moz-border-radius: 4px;
|
||||
-webkit-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
|
||||
#search-results li:last-child {
|
||||
border-bottom: none;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
#search-results li p {
|
||||
padding: 0;
|
||||
margin: 0.5em;
|
||||
}
|
||||
|
||||
#search-results .search-namespace {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#search-results li em {
|
||||
background: yellow;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
#search-results pre {
|
||||
margin: 0.5em;
|
||||
}
|
||||
|
||||
/* @end */
|
||||
|
@ -1,52 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
|
||||
|
||||
<title>Table of Contents - RDoc Documentation</title>
|
||||
|
||||
<link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
|
||||
|
||||
<script type="text/javascript">
|
||||
var rdoc_rel_prefix = "./";
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
|
||||
<script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
|
||||
|
||||
|
||||
<body class="indexpage">
|
||||
<h1>Table of Contents - RDoc Documentation</h1>
|
||||
|
||||
|
||||
<h2 id="classes">Classes/Modules</h2>
|
||||
<ul>
|
||||
<li class="class">
|
||||
<a href="FastImage.html">FastImage</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<h2 id="methods">Methods</h2>
|
||||
<ul>
|
||||
|
||||
<li class="method"><a href="FastImage.html#method-c-new">::new — FastImage</a>
|
||||
|
||||
<li class="method"><a href="FastImage.html#method-c-size">::size — FastImage</a>
|
||||
|
||||
<li class="method"><a href="FastImage.html#method-c-type">::type — FastImage</a>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
<footer id="validator-badges">
|
||||
<p><a href="http://validator.w3.org/check/referer">[Validate]</a>
|
||||
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 4.0.0.
|
||||
<p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
|
||||
</footer>
|
||||
|
BIN
test/fixtures/a.CR2
vendored
Normal file
BIN
test/fixtures/a.CRW
vendored
Normal file
BIN
test/fixtures/animated.gif
vendored
Normal file
After Width: | Height: | Size: 978 KiB |
BIN
test/fixtures/animated.png
vendored
Normal file
After Width: | Height: | Size: 62 KiB |
BIN
test/fixtures/animated_without_gct.gif
vendored
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
test/fixtures/avif/fox.avif
vendored
Normal file
After Width: | Height: | Size: 77 KiB |
BIN
test/fixtures/avif/hato.avif
vendored
Normal file
After Width: | Height: | Size: 253 KiB |
BIN
test/fixtures/avif/kimono.avif
vendored
Normal file
After Width: | Height: | Size: 83 KiB |
BIN
test/fixtures/avif/red_green_flash.avif
vendored
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
test/fixtures/avif/star.avifs
vendored
Normal file
BIN
test/fixtures/bad.jpg
vendored
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
test/fixtures/exif-orientation-testimages/jpg/ExifOrientation1.jpg
vendored
Executable file
After Width: | Height: | Size: 63 KiB |
BIN
test/fixtures/exif-orientation-testimages/jpg/ExifOrientation2.jpg
vendored
Executable file
After Width: | Height: | Size: 71 KiB |
BIN
test/fixtures/exif-orientation-testimages/jpg/ExifOrientation3.jpg
vendored
Executable file
After Width: | Height: | Size: 74 KiB |
BIN
test/fixtures/exif-orientation-testimages/jpg/ExifOrientation4.jpg
vendored
Executable file
After Width: | Height: | Size: 71 KiB |
BIN
test/fixtures/exif-orientation-testimages/jpg/ExifOrientation5.jpg
vendored
Executable file
After Width: | Height: | Size: 71 KiB |
BIN
test/fixtures/exif-orientation-testimages/jpg/ExifOrientation6.jpg
vendored
Executable file
After Width: | Height: | Size: 74 KiB |
BIN
test/fixtures/exif-orientation-testimages/jpg/ExifOrientation7.jpg
vendored
Executable file
After Width: | Height: | Size: 70 KiB |
BIN
test/fixtures/exif-orientation-testimages/jpg/ExifOrientation8.jpg
vendored
Executable file
After Width: | Height: | Size: 79 KiB |