exifr 1.3.10 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97fa3270a4d14398a02e6bd725753980ae12b74c2f0a6e3c160b840c59c7febf
4
- data.tar.gz: ec8ed547c94ad6dd83c0a07bb78530408d48637b18edfeb68dcb157a55c5c618
3
+ metadata.gz: 2799bf290120d558fe48495596a987705abb4bc394622e459d597a746c5b57d6
4
+ data.tar.gz: e84597a7f20fa3f45219372403851390679841a27f90e50b57bf4d0aba88d1be
5
5
  SHA512:
6
- metadata.gz: 3d10126d25f29634c46c8b5dce11ebd9dbc373c02fc892a74cdb8cbf6aa3cef8086e2a6be2eaac2a65bc83fa64a6f517617e22dc47bc4ea56db631b678a3ee3a
7
- data.tar.gz: b98ee638dc85ab51c1f86d5b9c34c417047a79d2abb920ee8a13e7decfaf8b66fb484d7d804461de276a3f87fd40f5e30c1a420e3b25e46db51e801f77acc9c3
6
+ metadata.gz: c6eef386c693e4ba34e715dbc8c1334a48dbc2d454abeda218beed9cf4184a868089576e5253f3f592a3c0ab4efc9e0315da908332bfb962b070f0519ea549db
7
+ data.tar.gz: 421ecfff8bffbb3300b48ab7e0c670f3980ce7d39c33c079d7b53096ae7527d6ee47edaf151396979f96c78bb7fd841c31227ab66ceea9dc0590fd90f8b76c14
data/lib/exifr/jpeg.rb CHANGED
@@ -29,11 +29,11 @@ module EXIFR
29
29
  attr_reader :app1s
30
30
 
31
31
  # +file+ is a filename or an IO object. Hint: use StringIO when working with slurped data like blobs.
32
- def initialize(file)
32
+ def initialize(file, load_thumbnails: true)
33
33
  if file.kind_of? String
34
- File.open(file, 'rb') { |io| examine(io) }
34
+ File.open(file, 'rb') { |io| examine(io, load_thumbnails: load_thumbnails) }
35
35
  else
36
- examine(file.dup)
36
+ examine(file.dup, load_thumbnails: load_thumbnails)
37
37
  end
38
38
  end
39
39
 
@@ -95,7 +95,7 @@ module EXIFR
95
95
  end
96
96
  end
97
97
 
98
- def examine(io)
98
+ def examine(io, load_thumbnails: true)
99
99
  io = Reader.new(io)
100
100
 
101
101
  unless io.getbyte == 0xFF && io.getbyte == 0xD8 # SOI
@@ -121,7 +121,7 @@ module EXIFR
121
121
 
122
122
  if app1 = @app1s.find { |d| d[0..5] == "Exif\0\0" }
123
123
  @exif_data = app1[6..-1]
124
- @exif = TIFF.new(StringIO.new(@exif_data))
124
+ @exif = TIFF.new(StringIO.new(@exif_data), load_thumbnails: load_thumbnails)
125
125
  end
126
126
  end
127
127
  end
data/lib/exifr/tiff.rb CHANGED
@@ -375,7 +375,7 @@ module EXIFR
375
375
  TAGS = [TAG_MAPPING.keys, TAG_MAPPING.values.map{|v|v.values}].flatten.uniq - IFD_TAGS
376
376
 
377
377
  # +file+ is a filename or an +IO+ object. Hint: use +StringIO+ when working with slurped data like blobs.
378
- def initialize(file)
378
+ def initialize(file, load_thumbnails: true)
379
379
  Data.open(file) do |data|
380
380
  @ifds = [IFD.new(data)]
381
381
  while ifd = @ifds.last.next
@@ -383,17 +383,21 @@ module EXIFR
383
383
  @ifds << ifd
384
384
  end
385
385
 
386
- @jpeg_thumbnails = @ifds.map do |v|
387
- if v.jpeg_interchange_format && v.jpeg_interchange_format_length
388
- start, length = v.jpeg_interchange_format, v.jpeg_interchange_format_length
389
- if Integer === start && Integer === length
390
- data[start..(start + length)]
391
- else
392
- EXIFR.logger.warn("Non numeric JpegInterchangeFormat data")
393
- nil
386
+ if load_thumbnails
387
+ @jpeg_thumbnails = @ifds.map do |v|
388
+ if v.jpeg_interchange_format && v.jpeg_interchange_format_length
389
+ start, length = v.jpeg_interchange_format, v.jpeg_interchange_format_length
390
+ if Integer === start && Integer === length
391
+ data[start..(start + length)]
392
+ else
393
+ EXIFR.logger.warn("Non numeric JpegInterchangeFormat data")
394
+ nil
395
+ end
394
396
  end
395
- end
396
- end.compact
397
+ end.compact
398
+ else
399
+ @jpeg_thumbnails = []
400
+ end
397
401
  end
398
402
  end
399
403
 
data/tests/jpeg_test.rb CHANGED
@@ -127,6 +127,13 @@ class JPEGTest < TestCase
127
127
  assert count > 0, 'no thumbnails found'
128
128
  end
129
129
 
130
+ def test_skippable_thumbnail
131
+ all_test_jpegs.each do |fname|
132
+ jpeg = JPEG.new(fname, load_thumbnails: false)
133
+ assert jpeg.thumbnail.nil?
134
+ end
135
+ end
136
+
130
137
  def test_gps_with_altitude
131
138
  t = JPEG.new(f('gps-altitude.jpg'))
132
139
 
data/tests/tiff_test.rb CHANGED
@@ -188,6 +188,13 @@ class TIFFTest < TestCase
188
188
  assert count > 0, 'no thumbnails found'
189
189
  end
190
190
 
191
+ def test_skippable_jpeg_thumbnails
192
+ all_test_tiffs.each do |fname|
193
+ t = TIFF.new(fname, load_thumbnails: false)
194
+ assert t.jpeg_thumbnails.empty?
195
+ end
196
+ end
197
+
191
198
  def test_should_not_loop_endlessly
192
199
  TIFF.new(f('endless-loop.exif'))
193
200
  assert true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exifr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.10
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - R.W. van 't Veer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-02 00:00:00.000000000 Z
11
+ date: 2023-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit
@@ -98,14 +98,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
98
  requirements:
99
99
  - - ">="
100
100
  - !ruby/object:Gem::Version
101
- version: 1.8.7
101
+ version: '2.0'
102
102
  required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
104
  - - ">="
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0'
107
107
  requirements: []
108
- rubygems_version: 3.3.7
108
+ rubygems_version: 3.4.6
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: Read EXIF from JPEG and TIFF images