fastimage 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.textile +5 -0
  3. data/lib/fastimage.rb +16 -8
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8bdd1b1858b1101956c8d27e85509ad1c68a436b
4
- data.tar.gz: 54021e4718ed2bf2480dd7972b59a8b6b711061c
3
+ metadata.gz: 286c430f0c94ceafdbcbe884ae9bee4252e549c0
4
+ data.tar.gz: c006bb076bdefba5bfdea4f024c8f327189b0b83
5
5
  SHA512:
6
- metadata.gz: cf0bfcba525fbacbb09919754faf51e3702bdfba09430601db181485e5626949a0f6ed8797a34e37e1f13d19100fe4bf020e6f3ef7c77aad40efe544f7f3007d
7
- data.tar.gz: bc307c6eda1000ad5a60be2bcfd98b18fa7bb33faf4bbf4db20c5fa4db3cb3653b55f39dba1653e83d0a8a8d3ec33ffe3a20da434d539993ae3b3447e8f3dea4
6
+ metadata.gz: cb7f192a5d7c2909c9b5275305608ed3c2e9c97e6d7fc9d0bd1386b08e3ccc29621a8cff9ba3b83eae4651fdbf8c27b2aa0cd70c5dea50efcd0912c7d82fcdc2
7
+ data.tar.gz: 72a91dbf2da909e0ebadbbd902fb7ffbbd3d7718073726fed3b23044bbc67134892008d227607d0f27e4b89ba464a451526a95c3bb047ed353c9addb98485a63
data/README.textile CHANGED
@@ -92,6 +92,10 @@ h2. Documentation
92
92
 
93
93
  "http://sdsykes.github.io/fastimage/rdoc/FastImage.html":http://sdsykes.github.io/fastimage/rdoc/FastImage.html
94
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
+
95
99
  h2. Benchmark
96
100
 
97
101
  It's way faster than conventional methods (for example the image_size gem) for most types of file when fetching over the wire.
@@ -151,6 +155,7 @@ h2. FastImage in other languages
151
155
  * "PHP by tommoor":https://github.com/tommoor/fastimage
152
156
  * "Node.js by ShogunPanda":https://github.com/ShogunPanda/fastimage
153
157
  * "Objective C by kylehickinson":https://github.com/kylehickinson/FastImage
158
+ * "Android by qstumn":https://github.com/qstumn/FastImageSize
154
159
 
155
160
  h2. Licence
156
161
 
data/lib/fastimage.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # coding: ASCII-8BIT
2
3
 
3
4
  # FastImage finds the size or type of an image given its uri.
@@ -190,6 +191,8 @@ class FastImage
190
191
 
191
192
  @property = @options[:type_only] ? :type : :size
192
193
 
194
+ @type, @state = nil
195
+
193
196
  if uri.respond_to?(:read)
194
197
  fetch_using_read(uri)
195
198
  elsif uri.start_with?('data:')
@@ -385,7 +388,9 @@ class FastImage
385
388
 
386
389
  def fetch_using_base64(uri)
387
390
  data = uri.split(',')[1]
388
- fetch_using_read StringIO.new(Base64.decode64(data))
391
+ decoded = Base64.decode64(data)
392
+ @content_length = decoded.size
393
+ fetch_using_read StringIO.new(decoded)
389
394
  end
390
395
 
391
396
  module StreamUtil # :nodoc:
@@ -431,7 +436,7 @@ class FastImage
431
436
  @strpos = 0
432
437
  end
433
438
 
434
- result = @str[@strpos..(@strpos + n - 1)]
439
+ @str[@strpos..(@strpos + n - 1)]
435
440
  end
436
441
 
437
442
  def read(n)
@@ -488,7 +493,7 @@ class FastImage
488
493
  :webp if @stream.peek(12)[8..11] == "WEBP"
489
494
  when "<s"
490
495
  :svg
491
- when "<?"
496
+ when /<[?!]/
492
497
  # Peek 10 more chars each time, and if end of file is reached just raise
493
498
  # unknown. We assume the <svg tag cannot be within 10 chars of the end of
494
499
  # the file, and is within the first 250 chars.
@@ -518,6 +523,7 @@ class FastImage
518
523
  end
519
524
 
520
525
  def parse_size_for_jpeg
526
+ exif = nil
521
527
  loop do
522
528
  @state = case @state
523
529
  when nil
@@ -533,7 +539,7 @@ class FastImage
533
539
  io = StringIO.new(data)
534
540
  if io.read(4) == "Exif"
535
541
  io.read(2)
536
- @exif = Exif.new(IOStream.new(io)) rescue nil
542
+ exif = Exif.new(IOStream.new(io)) rescue nil
537
543
  end
538
544
  :started
539
545
  when 0xe0..0xef
@@ -553,8 +559,8 @@ class FastImage
553
559
  @stream.skip(3)
554
560
  height = @stream.read_int
555
561
  width = @stream.read_int
556
- width, height = height, width if @exif && @exif.rotated?
557
- return [width, height, @exif ? @exif.orientation : 1]
562
+ width, height = height, width if exif && exif.rotated?
563
+ return [width, height, exif ? exif.orientation : 1]
558
564
  end
559
565
  end
560
566
  end
@@ -575,7 +581,7 @@ class FastImage
575
581
 
576
582
  def parse_size_for_webp
577
583
  vp8 = @stream.read(16)[12..15]
578
- len = @stream.read(4).unpack("V")
584
+ _len = @stream.read(4).unpack("V")
579
585
  case vp8
580
586
  when "VP8 "
581
587
  parse_size_vp8
@@ -617,6 +623,7 @@ class FastImage
617
623
 
618
624
  def initialize(stream)
619
625
  @stream = stream
626
+ @width, @height, @orientation = nil
620
627
  parse_exif
621
628
  end
622
629
 
@@ -696,6 +703,7 @@ class FastImage
696
703
  class Svg # :nodoc:
697
704
  def initialize(stream)
698
705
  @stream = stream
706
+ @width, @height, @ratio, @viewbox_width, @viewbox_height = nil
699
707
  parse_svg
700
708
  end
701
709
 
@@ -732,7 +740,7 @@ class FastImage
732
740
  return if @width
733
741
  elsif attr_name.join =~ /viewbox/i
734
742
  values = attr_value.split(/\s/)
735
- if values[2].to_f > 0 && values[3].to_f > 0
743
+ if values[2].to_f > 0 && values[3].to_f > 0
736
744
  @ratio = values[2].to_f / values[3].to_f
737
745
  @viewbox_width = values[2].to_i
738
746
  @viewbox_height = values[3].to_i
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.1.0
4
+ version: 2.1.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: 2017-02-23 00:00:00.000000000 Z
11
+ date: 2017-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fakeweb