fastimage 2.3.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa0337307f5e98ae916e46768e148812f0f6dbb93a1c67d193ca981540779336
4
- data.tar.gz: 8600c44df8eed5762ec526709d46e32841a099c0c453e7c255c2a87611dcb822
3
+ metadata.gz: e4eedb99b6314f24fb47381046bf63595b90b8eb8045a6b9b238a92acebc00ba
4
+ data.tar.gz: 10db6080223fb596a5fcfc904563a5f25b8209af1c4166260831e7aef9d7613e
5
5
  SHA512:
6
- metadata.gz: 57b4e77535ee1022ec9b1d3209536729dd5e980c2799fc6987d3c91731f5dd4dce3d93ef29f97c8762b6021b12795554efbc3ca1db7a49713aa119bdb5df5088
7
- data.tar.gz: 83741942ce879586ae813fda60da760bee079ff1000dbbf7ee118b2513d579ae4cff8acf98de0bafe5313d429352053380e8d0293a101b0a3b1a799ce457f5a1
6
+ metadata.gz: eae9ad37f27b853c2927183802b015ca6a066e413a112d80bb119603944d07d9fba5aac36712bc12c12acb327e3031a6b8c6875120e6f8de501e0526d4e2be14
7
+ data.tar.gz: 2b8e2add3af30fe7e856b84e18ba6f9425fb939e5e789f1601fb360abb91ee5197b15adaa6cff79a2bdb89ea7a9d95306ebc0513c4882cd0a30b7ab3261173d2
data/README.md CHANGED
@@ -96,38 +96,78 @@ http://sdsykes.github.io/fastimage/rdoc/FastImage.html
96
96
 
97
97
  ## Maintainer
98
98
 
99
- FastImage is maintained by Stephen Sykes (`sdsykes). Support this project by using [LibPixel](https://libpixel.com) cloud based image resizing and processing service.
99
+ FastImage is maintained by Stephen Sykes (sdsykes). SamSaffron also helps out from time to time (thanks!).
100
100
 
101
101
  ## Benchmark
102
102
 
103
- It's way faster than conventional methods (for example the image_size gem) for most types of file when fetching over the wire.
103
+ 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.
104
104
 
105
105
  ```ruby
106
- irb> uri = "http://upload.wikimedia.org/wikipedia/commons/b/b4/Mardin_1350660_1350692_33_images.jpg"
107
- irb> puts Benchmark.measure {open(uri, 'rb') {|fh| p ImageSize.new(fh).size}}
106
+ require 'benchmark'
107
+ require 'fastimage'
108
+ require 'open-uri'
109
+
110
+ uri = "http://upload.wikimedia.org/wikipedia/commons/b/b4/Mardin_1350660_1350692_33_images.jpg"
111
+ puts Benchmark.measure {URI.open(uri, 'rb') {|fh| p FastImage.size(fh)}}
108
112
  [9545, 6623]
109
- 0.680000 0.250000 0.930000 ( 7.571887)
113
+ 0.059088 0.067694 0.126782 ( 0.808131)
110
114
 
111
- irb> puts Benchmark.measure {p FastImage.size(uri)}
115
+ puts Benchmark.measure {p FastImage.size(uri)}
112
116
  [9545, 6623]
113
- 0.010000 0.000000 0.010000 ( 0.090640)
117
+ 0.006198 0.001563 0.007761 ( 0.162021)
114
118
  ```
115
119
 
116
- 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.
120
+ 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.
121
+
122
+ You'll see similar excellent results for the other file types.
123
+
124
+ ```ruby
125
+ require 'benchmark'
126
+ require 'fastimage'
127
+ require 'open-uri'
128
+
129
+ uri = "https://upload.wikimedia.org/wikipedia/commons/a/a9/Augustine_Herrman_1670_Map_Virginia_Maryland.tiff"
130
+ puts Benchmark.measure {URI.open(uri, 'rb') {|fh| p FastImage.size(fh)}}
131
+ [12805, 10204]
132
+ 1.332587 2.049915 3.382502 ( 19.925270)
117
133
 
118
- You'll see similar excellent results for the other file types, except for TIFF. Unfortunately TIFFs tend to have their
119
- metadata towards the end of the file, so it makes little difference to do a minimal fetch. The result shown below is
120
- mostly dependent on the exact internet conditions during the test, and little to do with the library used.
134
+ puts Benchmark.measure {p FastImage.size(uri)}
135
+ [12805, 10204]
136
+ 0.004593 0.000924 0.005517 ( 0.100592)
137
+ ```
138
+
139
+ Some tiff files however do not have their metadata near the start of the file.
121
140
 
122
141
  ```ruby
123
- irb> uri = "http://upload.wikimedia.org/wikipedia/commons/1/11/Shinbutsureijoushuincho.tiff"
124
- irb> puts Benchmark.measure {open(uri, 'rb') {|fh| p ImageSize.new(fh).size}}
125
- [1120, 1559]
126
- 1.080000 0.370000 1.450000 ( 13.766962)
127
-
128
- irb> puts Benchmark.measure {p FastImage.size(uri)}
129
- [1120, 1559]
130
- 3.490000 3.810000 7.300000 ( 11.754315)
142
+ require 'benchmark'
143
+ require 'fastimage'
144
+ require 'open-uri'
145
+
146
+ uri = "https://upload.wikimedia.org/wikipedia/commons/1/14/Center-Filled_LIMA.tif"
147
+ puts Benchmark.measure {URI.open(uri, 'rb') {|fh| p FastImage.size(fh)}}
148
+ [22841, 19404]
149
+ 0.350304 0.321104 0.671408 ( 3.053605)
150
+
151
+ puts Benchmark.measure {p FastImage.size(uri)}
152
+ [22841, 19404]
153
+ 0.163443 0.214301 0.377744 ( 2.880414)
154
+ ```
155
+
156
+ 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).
157
+
158
+ ```ruby
159
+ require 'benchmark'
160
+ require 'image_size/uri'
161
+ require 'fastimage'
162
+
163
+ uri = "https://upload.wikimedia.org/wikipedia/commons/1/14/Center-Filled_LIMA.tif"
164
+ puts Benchmark.measure {p ImageSize.url(uri).size }
165
+ [22841, 19404]
166
+ 0.008983 0.001311 0.010294 ( 0.128986)
167
+
168
+ puts Benchmark.measure {p FastImage.size(uri)}
169
+ [22841, 19404]
170
+ 0.163443 0.214301 0.377744 ( 2.880414)
131
171
  ```
132
172
 
133
173
  ## Tests
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class FastImage
4
- VERSION = '2.3.0'
4
+ VERSION = '2.3.1'
5
5
  end
data/lib/fastimage.rb CHANGED
@@ -321,6 +321,7 @@ class FastImage
321
321
  res.read_body do |str|
322
322
  Fiber.yield str
323
323
  end
324
+ nil
324
325
  end
325
326
 
326
327
  case res['content-encoding']
@@ -335,6 +336,7 @@ class FastImage
335
336
  while data = gzip.readline
336
337
  Fiber.yield data
337
338
  end
339
+ nil
338
340
  end
339
341
  end
340
342
 
@@ -388,12 +390,14 @@ class FastImage
388
390
  Fiber.yield str
389
391
  offset += LocalFileChunkSize
390
392
  end
393
+ nil
391
394
  end
392
395
  else
393
396
  read_fiber = Fiber.new do
394
397
  while str = readable.read(LocalFileChunkSize)
395
398
  Fiber.yield str
396
399
  end
400
+ nil
397
401
  end
398
402
  end
399
403
 
@@ -471,6 +475,9 @@ class FastImage
471
475
  include StreamUtil
472
476
  attr_reader :pos
473
477
 
478
+ # read_fiber should return nil if it no longer has anything to return when resumed
479
+ # so the result of the whole Fiber block should be set to be nil in case yield is no
480
+ # longer called
474
481
  def initialize(read_fiber)
475
482
  @read_fiber = read_fiber
476
483
  @pos = 0
@@ -484,7 +491,6 @@ class FastImage
484
491
  unused_str = @str[@strpos..-1]
485
492
 
486
493
  new_string = @read_fiber.resume
487
- new_string = @read_fiber.resume if new_string.is_a? Net::ReadAdapter
488
494
  raise CannotParseImage if !new_string
489
495
  # we are dealing with bytes here, so force the encoding
490
496
  new_string.force_encoding("ASCII-8BIT") if new_string.respond_to? :force_encoding
@@ -573,7 +579,7 @@ class FastImage
573
579
  # the file, and is within the first 1000 chars.
574
580
  begin
575
581
  :svg if (1..100).detect {|n| @stream.peek(10 * n).include?("<svg")}
576
- rescue FiberError
582
+ rescue FiberError, CannotParseImage
577
583
  nil
578
584
  end
579
585
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastimage
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Sykes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-24 00:00:00.000000000 Z
11
+ date: 2024-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fakeweb-fi
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
- rubygems_version: 3.3.7
101
+ rubygems_version: 3.4.10
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: FastImage - Image info fast