fastimage 2.2.6 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastimage
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.6
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Sykes
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2021-02-28 00:00:00.000000000 Z
10
+ date: 2025-01-03 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: fakeweb-fi
@@ -72,17 +71,36 @@ email: sdsykes@gmail.com
72
71
  executables: []
73
72
  extensions: []
74
73
  extra_rdoc_files:
75
- - README.textile
74
+ - README.md
76
75
  files:
77
76
  - MIT-LICENSE
78
- - README.textile
77
+ - README.md
79
78
  - lib/fastimage.rb
79
+ - lib/fastimage/fastimage.rb
80
+ - lib/fastimage/fastimage_parsing/avif.rb
81
+ - lib/fastimage/fastimage_parsing/bmp.rb
82
+ - lib/fastimage/fastimage_parsing/exif.rb
83
+ - lib/fastimage/fastimage_parsing/fiber_stream.rb
84
+ - lib/fastimage/fastimage_parsing/gif.rb
85
+ - lib/fastimage/fastimage_parsing/heic.rb
86
+ - lib/fastimage/fastimage_parsing/ico.rb
87
+ - lib/fastimage/fastimage_parsing/image_base.rb
88
+ - lib/fastimage/fastimage_parsing/iso_bmff.rb
89
+ - lib/fastimage/fastimage_parsing/jpeg.rb
90
+ - lib/fastimage/fastimage_parsing/jxl.rb
91
+ - lib/fastimage/fastimage_parsing/jxlc.rb
92
+ - lib/fastimage/fastimage_parsing/png.rb
93
+ - lib/fastimage/fastimage_parsing/psd.rb
94
+ - lib/fastimage/fastimage_parsing/stream_util.rb
95
+ - lib/fastimage/fastimage_parsing/svg.rb
96
+ - lib/fastimage/fastimage_parsing/tiff.rb
97
+ - lib/fastimage/fastimage_parsing/type_parser.rb
98
+ - lib/fastimage/fastimage_parsing/webp.rb
80
99
  - lib/fastimage/version.rb
81
100
  homepage: http://github.com/sdsykes/fastimage
82
101
  licenses:
83
102
  - MIT
84
103
  metadata: {}
85
- post_install_message:
86
104
  rdoc_options:
87
105
  - "--charset=UTF-8"
88
106
  require_paths:
@@ -98,8 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
116
  - !ruby/object:Gem::Version
99
117
  version: '0'
100
118
  requirements: []
101
- rubygems_version: 3.1.6
102
- signing_key:
119
+ rubygems_version: 3.6.2
103
120
  specification_version: 4
104
121
  summary: FastImage - Image info fast
105
122
  test_files: []
data/README.textile DELETED
@@ -1,163 +0,0 @@
1
- !https://img.shields.io/gem/dt/fastimage.svg!:https://rubygems.org/gems/fastimage
2
- !https://travis-ci.org/sdsykes/fastimage.svg?branch=master!:https://travis-ci.org/sdsykes/fastimage
3
-
4
- h1. FastImage
5
-
6
- h4. FastImage finds the size or type of an image given its uri by fetching as little as needed
7
-
8
- h2. The problem
9
-
10
- 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.
11
-
12
- But the image is not locally stored - it's on another asset server, or in the cloud - at Amazon S3 for example.
13
-
14
- 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.
15
-
16
- FastImage does this minimal fetch for image types GIF, JPEG, PNG, TIFF, BMP, ICO, CUR, PSD, SVG and WEBP. And it doesn't rely on installing external libraries such as RMagick (which relies on ImageMagick or GraphicsMagick) or ImageScience (which relies on FreeImage).
17
-
18
- You only need supply the uri, and FastImage will do the rest.
19
-
20
- h2. Features
21
-
22
- FastImage can also read local (and other) files - anything that is not parseable as a URI will be interpreted as a filename, and FastImage will attempt to open it with @File#open@.
23
-
24
- FastImage will also automatically read from any object that responds to @:read@ - for instance an IO object if that is passed instead of a URI.
25
-
26
- FastImage will follow up to 4 HTTP redirects to get the image.
27
-
28
- FastImage will 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.
29
-
30
- You can add a timeout to the request which will limit the request time by passing @:timeout => number_of_seconds@.
31
-
32
- FastImage normally replies with @nil@ if it encounters an error, but you can pass @:raise_on_failure => true@ to get an exception.
33
-
34
- 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.
35
-
36
- 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'}@.
37
-
38
- FastImage can give you information about the parsed display orientation of an image with Exif data (jpeg or tiff).
39
-
40
- FastImage also handles "Data URIs":https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs correctly.
41
-
42
- h2. Security
43
-
44
- As of v1.6.7 FastImage no longer uses @openuri@ to open files, but directly calls @File.open@. Take care to sanitise the strings passed to FastImage; it will try to read from whatever is passed.
45
-
46
- h2. Examples
47
-
48
- <pre lang="ruby"><code>
49
- require 'fastimage'
50
-
51
- FastImage.size("http://stephensykes.com/images/ss.com_x.gif")
52
- => [266, 56] # width, height
53
- FastImage.type("http://stephensykes.com/images/pngimage")
54
- => :png
55
- FastImage.type("/some/local/file.gif")
56
- => :gif
57
- FastImage.size("http://upload.wikimedia.org/wikipedia/commons/b/b4/Mardin_1350660_1350692_33_images.jpg", :raise_on_failure=>true, :timeout=>0.1)
58
- => FastImage::ImageFetchFailure: FastImage::ImageFetchFailure
59
- FastImage.size("http://upload.wikimedia.org/wikipedia/commons/b/b4/Mardin_1350660_1350692_33_images.jpg", :raise_on_failure=>true, :timeout=>2.0)
60
- => [9545, 6623]
61
- FastImage.new("http://stephensykes.com/images/pngimage").content_length
62
- => 432
63
- FastImage.size("http://stephensykes.com/images/ss.com_x.gif", :http_header => {'User-Agent' => 'Fake Browser'})
64
- => [266, 56]
65
- FastImage.new("http://stephensykes.com/images/ExifOrientation3.jpg").orientation
66
- => 3
67
- FastImage.size("data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
68
- => [1, 1]
69
- </code></pre>
70
-
71
- h2. Installation
72
-
73
- h4. Required Ruby version
74
-
75
- FastImage version 2.0.0 and above work with Ruby 1.9.2 and above.
76
-
77
- FastImage version 1.9.0 was the last version that supported Ruby 1.8.7.
78
-
79
- h4. Gem
80
-
81
- bc. gem install fastimage
82
-
83
- h4. Rails
84
-
85
- Add fastimage to your Gemfile, and bundle.
86
-
87
- bc. gem 'fastimage'
88
-
89
- Then you're off - just use @FastImage.size()@ and @FastImage.type()@ in your code as in the examples.
90
-
91
- h2. Documentation
92
-
93
- "http://sdsykes.github.io/fastimage/rdoc/FastImage.html":http://sdsykes.github.io/fastimage/rdoc/FastImage.html
94
-
95
- h2. Maintainer
96
-
97
- FastImage is maintained by Stephen Sykes (@sdsykes). Support this project by using "LibPixel":https://libpixel.com cloud based image resizing and processing service.
98
-
99
- h2. Benchmark
100
-
101
- It's way faster than conventional methods (for example the image_size gem) for most types of file when fetching over the wire.
102
-
103
- <pre lang="ruby"><code>
104
- irb> uri = "http://upload.wikimedia.org/wikipedia/commons/b/b4/Mardin_1350660_1350692_33_images.jpg"
105
- irb> puts Benchmark.measure {open(uri, 'rb') {|fh| p ImageSize.new(fh).size}}
106
- [9545, 6623]
107
- 0.680000 0.250000 0.930000 ( 7.571887)
108
-
109
- irb> puts Benchmark.measure {p FastImage.size(uri)}
110
- [9545, 6623]
111
- 0.010000 0.000000 0.010000 ( 0.090640)
112
- </code></pre>
113
-
114
- 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.
115
-
116
- You'll see similar excellent results for the other file types, except for TIFF. Unfortunately TIFFs tend to have their
117
- metadata towards the end of the file, so it makes little difference to do a minimal fetch. The result shown below is
118
- mostly dependent on the exact internet conditions during the test, and little to do with the library used.
119
-
120
- <pre lang="ruby"><code>
121
- irb> uri = "http://upload.wikimedia.org/wikipedia/commons/1/11/Shinbutsureijoushuincho.tiff"
122
- irb> puts Benchmark.measure {open(uri, 'rb') {|fh| p ImageSize.new(fh).size}}
123
- [1120, 1559]
124
- 1.080000 0.370000 1.450000 ( 13.766962)
125
-
126
- irb> puts Benchmark.measure {p FastImage.size(uri)}
127
- [1120, 1559]
128
- 3.490000 3.810000 7.300000 ( 11.754315)
129
- </code></pre>
130
-
131
- h2. Tests
132
-
133
- You'll need to @gem install fakeweb@ and possibly also @gem install test-unit@ to be able to run the tests.
134
-
135
- bc.. $ ruby test/test.rb
136
- Run options:
137
-
138
- # Running tests:
139
-
140
- Finished tests in 1.033640s, 23.2189 tests/s, 82.2337 assertions/s.
141
- 24 tests, 85 assertions, 0 failures, 0 errors, 0 skips
142
-
143
- h2. References
144
-
145
- * "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/
146
- * "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/
147
- * "imagesize gem":https://rubygems.org/gems/imagesize
148
- * "EXIF Reader":https://github.com/remvee/exifr
149
-
150
- h2. FastImage in other languages
151
-
152
- * "Python by bmuller":https://github.com/bmuller/fastimage
153
- * "Swift by kaishin":https://github.com/kaishin/ImageScout
154
- * "Go by rubenfonseca":https://github.com/rubenfonseca/fastimage
155
- * "PHP by tommoor":https://github.com/tommoor/fastimage
156
- * "Node.js by ShogunPanda":https://github.com/ShogunPanda/fastimage
157
- * "Objective C by kylehickinson":https://github.com/kylehickinson/FastImage
158
- * "Android by qstumn":https://github.com/qstumn/FastImageSize
159
- * "Flutter by ky1vstar":https://github.com/ky1vstar/fastimage.dart
160
-
161
- h2. Licence
162
-
163
- MIT, see file "MIT-LICENSE":MIT-LICENSE