fastimage 1.6.7 → 1.6.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0cc039d623dc912c65fb475ac7fcf40e6908075
4
- data.tar.gz: d0904edca54dbb88a60dcfc3e38405c7133efcdf
3
+ metadata.gz: 47e50479e458978b758e62aaeea44345c05a27ea
4
+ data.tar.gz: ee7b1918db731c9bee8c1f08bd0cc3515ec6c348
5
5
  SHA512:
6
- metadata.gz: 70886f6c9b00ee5a47af1beb69fdccaa6d1611ee264eba196c5773e2b0f6959b7cec9dc60c1540851788190d2e64c763094be8cd9ff44d0ca0ab52ea7461f6d7
7
- data.tar.gz: 14f89c0602a5d7602d28d1e2fad44c47009afb004f4635f44fc7131ad2b2a49df4c9062041799556e04297ac8c214afe15b3608284763d53282dd93294d4edcf
6
+ metadata.gz: 590b19d10a62e9c34cd7777f10999498e787acd5b09ce103578f9d777fdb73e670a78cebafc6ad61a80c1ac08947a5dbff96d4a8e1589982fa6abe065592f4a9
7
+ data.tar.gz: 41f069d44b395574c5c5c60b10bde728d5cae4d9d6e7fee195ebef5c541476efeb102830dea89a6b09c64ce87b349cd05758792166ee81b5a435d32890b831ef
data/README.textile CHANGED
@@ -26,7 +26,7 @@ instance an IO object if that is passed instead of a URI.
26
26
 
27
27
  FastImage will follow up to 4 HTTP redirects to get the image.
28
28
 
29
- FastImage will obey the http_proxy setting in your environment to route requests via a proxy.
29
+ 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.
30
30
 
31
31
  You can add a timeout to the request which will limit the request time by passing :timeout => number_of_seconds.
32
32
 
@@ -142,4 +142,5 @@ Pull requests and suggestions are always welcome. Thanks to all the contributors
142
142
  * @muffinista
143
143
  * @marcandre
144
144
  * @apanzerj
145
+ * @forresty
145
146
 
data/lib/fastimage.rb CHANGED
@@ -63,9 +63,9 @@ class FastImage
63
63
  class CannotParseImage < FastImageException # :nodoc:
64
64
  end
65
65
 
66
- DefaultTimeout = 2
66
+ DefaultTimeout = 2 unless const_defined?(:DefaultTimeout)
67
67
 
68
- LocalFileChunkSize = 256
68
+ LocalFileChunkSize = 256 unless const_defined?(:LocalFileChunkSize)
69
69
 
70
70
  # Returns an array containing the width and height of the image.
71
71
  # It will return nil if the image could not be fetched, or if the image type was not recognised.
@@ -160,6 +160,7 @@ class FastImage
160
160
  def initialize(uri, options={})
161
161
  @property = options[:type_only] ? :type : :size
162
162
  @timeout = options[:timeout] || DefaultTimeout
163
+ @proxy_url = options[:proxy]
163
164
  @uri = uri
164
165
 
165
166
  if uri.respond_to?(:read)
@@ -250,7 +251,7 @@ class FastImage
250
251
  end
251
252
  end
252
253
  end
253
-
254
+
254
255
  parse_packets FiberStream.new(read_fiber)
255
256
 
256
257
  break # needed to actively quit out of the fetch
@@ -259,7 +260,11 @@ class FastImage
259
260
 
260
261
  def proxy_uri
261
262
  begin
262
- proxy = ENV['http_proxy'] && ENV['http_proxy'] != "" ? Addressable::URI.parse(ENV['http_proxy']) : nil
263
+ if @proxy_url
264
+ proxy = Addressable::URI.parse(@proxy_url)
265
+ else
266
+ proxy = ENV['http_proxy'] && ENV['http_proxy'] != "" ? Addressable::URI.parse(ENV['http_proxy']) : nil
267
+ end
263
268
  rescue Addressable::URI::InvalidURIError
264
269
  proxy = nil
265
270
  end
@@ -404,7 +409,7 @@ class FastImage
404
409
  :webp
405
410
  else
406
411
  raise UnknownImageType
407
- end
412
+ end
408
413
  else
409
414
  raise UnknownImageType
410
415
  end
@@ -493,18 +498,18 @@ class FastImage
493
498
  nil
494
499
  end
495
500
  end
496
-
501
+
497
502
  def parse_size_vp8
498
503
  w, h = @stream.read(10).unpack("@6vv")
499
504
  [w & 0x3fff, h & 0x3fff]
500
505
  end
501
-
506
+
502
507
  def parse_size_vp8l
503
508
  @stream.read(1) # 0x2f
504
509
  b1, b2, b3, b4 = @stream.read(4).bytes.to_a
505
510
  [1 + (((b2 & 0x3f) << 8) | b1), 1 + (((b4 & 0xF) << 10) | (b3 << 2) | ((b2 & 0xC0) >> 6))]
506
511
  end
507
-
512
+
508
513
  def parse_size_vp8x
509
514
  flags = @stream.read(4).unpack("C")[0]
510
515
  b1, b2, b3, b4, b5, b6 = @stream.read(6).unpack("CCCCCC")
@@ -514,7 +519,7 @@ class FastImage
514
519
  # parse exif for orientation
515
520
  # TODO: find or create test images for this
516
521
  end
517
-
522
+
518
523
  return [width, height]
519
524
  end
520
525
 
data/lib/fastimage/fbr.rb CHANGED
@@ -64,4 +64,3 @@ unless defined? Fiber
64
64
  end
65
65
  end
66
66
  end
67
-
data/test/test.rb CHANGED
@@ -60,9 +60,9 @@ BadFixtures.each do |fn|
60
60
  end
61
61
 
62
62
  GzipTestImg = "gzipped.jpg"
63
- FakeWeb.register_uri(:get, "#{TestUrl}#{GzipTestImg}", :body => File.join(FixturePath, GzipTestImg), :content_encoding => "gzip")
63
+ FakeWeb.register_uri(:get, "#{TestUrl}#{GzipTestImg}", :body => File.join(FixturePath, GzipTestImg), :content_encoding => "gzip")
64
64
  GzipTestImgTruncated = "truncated_gzipped.jpg"
65
- FakeWeb.register_uri(:get, "#{TestUrl}#{GzipTestImgTruncated}", :body => File.join(FixturePath, GzipTestImgTruncated), :content_encoding => "gzip")
65
+ FakeWeb.register_uri(:get, "#{TestUrl}#{GzipTestImgTruncated}", :body => File.join(FixturePath, GzipTestImgTruncated), :content_encoding => "gzip")
66
66
  GzipTestImgSize = [970, 450]
67
67
 
68
68
  class FastImageTest < Test::Unit::TestCase
@@ -245,11 +245,18 @@ class FastImageTest < Test::Unit::TestCase
245
245
  assert_equal actual_size, size
246
246
  end
247
247
 
248
+ def test_should_fetch_via_proxy_option
249
+ file = "test.gif"
250
+ actual_size = GoodFixtures[file][1]
251
+ size = FastImage.size(TestUrl + file, :proxy => "http://my.proxy.host:8080")
252
+ assert_equal actual_size, size
253
+ end
254
+
248
255
  def test_should_handle_https_image
249
256
  size = FastImage.size(HTTPSImage)
250
257
  assert_equal HTTPSImageInfo[1], size
251
258
  end
252
-
259
+
253
260
  require 'pathname'
254
261
  def test_should_handle_pathname
255
262
  # bad.jpg does not have the size info in the first 256 bytes
@@ -258,7 +265,7 @@ class FastImageTest < Test::Unit::TestCase
258
265
  path = Pathname.new(File.join(FixturePath, "bad.jpg"))
259
266
  assert_equal([500,500], FastImage.size(path))
260
267
  end
261
-
268
+
262
269
  def test_should_report_type_and_size_correctly_for_stringios
263
270
  GoodFixtures.each do |fn, info|
264
271
  string = File.read(File.join(FixturePath, fn))
@@ -267,7 +274,7 @@ class FastImageTest < Test::Unit::TestCase
267
274
  assert_equal info[1], FastImage.size(stringio)
268
275
  end
269
276
  end
270
-
277
+
271
278
  def test_gzipped_file
272
279
  url = "http://example.nowhere/#{GzipTestImg}"
273
280
  assert_equal([970, 450], FastImage.size(url))
@@ -279,7 +286,7 @@ class FastImageTest < Test::Unit::TestCase
279
286
  FastImage.size(url, :raise_on_failure => true)
280
287
  end
281
288
  end
282
-
289
+
283
290
  def test_cant_access_shell
284
291
  url = "|echo>shell_test"
285
292
  %x{rm -f shell_test}
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: 1.6.7
4
+ version: 1.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Sykes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-28 00:00:00.000000000 Z
11
+ date: 2015-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -72,6 +72,20 @@ dependencies:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: test-unit
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
75
89
  description: FastImage finds the size or type of an image given its uri by fetching
76
90
  as little as needed.
77
91
  email: sdsykes@gmail.com
@@ -130,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
144
  version: '0'
131
145
  requirements: []
132
146
  rubyforge_project:
133
- rubygems_version: 2.2.2
147
+ rubygems_version: 2.4.5
134
148
  signing_key:
135
149
  specification_version: 4
136
150
  summary: FastImage - Image info fast