exifr 0.10.3 → 0.10.4

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.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ EXIF Reader 0.10.4
2
+ * Thumbnail extraction; [#15317] Please add thumbnail extraction
3
+
1
4
  EXIF Reader 0.10.3
2
5
  * YAML friendly; can now safely (de)serialize
3
6
 
data/Rakefile CHANGED
@@ -6,9 +6,22 @@ require 'rake/testtask'
6
6
 
7
7
  task :default => :test
8
8
 
9
+ desc 'Generate site'
10
+ task :site => :rdoc do
11
+ system 'rsync -av --delete doc/ remvee@rubyforge.org:/var/www/gforge-projects/exifr'
12
+ end
13
+
14
+ desc "Tag current trunk. Use VERSION to provide a version spec."
15
+ task :tag do
16
+ version = ENV['VERSION'] or raise 'provide VERSION'
17
+ base = 'svn+ssh://remvee@rubyforge.org/var/svn/exifr'
18
+ trunk, tag = base + "/trunk", base + "/tags/#{version}"
19
+ system *(%w(svn copy -m) << "tagged release #{version}" << trunk << tag)
20
+ end
21
+
9
22
  spec = Gem::Specification.new do |s|
10
23
  s.name = 'exifr'
11
- s.version = '0.10.3'
24
+ s.version = '0.10.4'
12
25
  s.author = "R.W. van 't Veer"
13
26
  s.email = 'remco@remvee.net'
14
27
  s.homepage = 'http://exifr.rubyforge.org/'
@@ -34,6 +34,11 @@ module EXIFR
34
34
  def exif?
35
35
  !exif.nil?
36
36
  end
37
+
38
+ # Return thumbnail data when available.
39
+ def thumbnail
40
+ @exif && @exif.jpeg_thumbnails && @exif.jpeg_thumbnails.first
41
+ end
37
42
 
38
43
  # Dispatch to EXIF. When no EXIF data is available but the +method+ does exist
39
44
  # for EXIF data +nil+ will be returned.
@@ -37,6 +37,9 @@ module EXIFR
37
37
  class TIFF
38
38
  include Enumerable
39
39
 
40
+ # JPEG thumbnails
41
+ attr_reader :jpeg_thumbnails
42
+
40
43
  TAG_MAPPING = {} # :nodoc:
41
44
  TAG_MAPPING.merge!({
42
45
  :image => {
@@ -317,6 +320,13 @@ module EXIFR
317
320
 
318
321
  @ifds = [IFD.new(data)]
319
322
  while ifd = @ifds.last.next; @ifds << ifd; end
323
+
324
+ @jpeg_thumbnails = @ifds.map do |ifd|
325
+ if ifd.jpeg_interchange_format && ifd.jpeg_interchange_format_length
326
+ start, length = ifd.jpeg_interchange_format, ifd.jpeg_interchange_format_length
327
+ data[start..(start + length)]
328
+ end
329
+ end.compact
320
330
  end
321
331
 
322
332
  # Number of images.
@@ -413,6 +423,7 @@ module EXIFR
413
423
  private
414
424
  def add_field(field)
415
425
  return unless tag = TAG_MAPPING[@type][field.tag]
426
+
416
427
  if IFD_TAGS.include? tag
417
428
  @fields[tag] = IFD.new(@data, field.offset, tag)
418
429
  else
@@ -21,9 +21,19 @@ def all_test_exifs
21
21
  end
22
22
 
23
23
  def all_test_tiffs
24
- Dir[f('*.tif')]
24
+ Dir[f('*.tif')] + all_test_exifs
25
25
  end
26
26
 
27
27
  def f(fname)
28
28
  "#{File.dirname(__FILE__)}/data/#{fname}"
29
29
  end
30
+
31
+ def assert_literally_equal(expected, actual, *args)
32
+ assert_equal expected.to_s, actual.to_s, *args
33
+ end
34
+
35
+ class Hash
36
+ def to_s
37
+ keys.map{|k| k.to_s}.sort.map{|k| "#{k.inspect} => #{self[k].inspect}" }.join(', ')
38
+ end
39
+ end
@@ -60,4 +60,19 @@ class TestJPEG < Test::Unit::TestCase
60
60
  def test_multiple_app1
61
61
  assert JPEG.new(f('multiple-app1.jpg')).exif?
62
62
  end
63
+
64
+ def test_thumbnail
65
+ count = 0
66
+ all_test_jpegs.each do |fname|
67
+ jpeg = JPEG.new(fname)
68
+ unless jpeg.thumbnail.nil?
69
+ assert_nothing_raised 'thumbnail not a JPEG' do
70
+ JPEG.new(StringIO.new(jpeg.thumbnail))
71
+ end
72
+ count += 1
73
+ end
74
+ end
75
+
76
+ assert count > 0, 'no thumbnails found'
77
+ end
63
78
  end
@@ -116,7 +116,7 @@ class TestTIFF < Test::Unit::TestCase
116
116
  all_test_tiffs.each do |fname|
117
117
  t = TIFF.new(fname)
118
118
  TIFF::TAGS.each do |key|
119
- assert_equal t.send(key), t.to_hash[key]
119
+ assert_literally_equal t.send(key), t.to_hash[key], "#{key} not equal"
120
120
  end
121
121
  end
122
122
  end
@@ -133,7 +133,23 @@ class TestTIFF < Test::Unit::TestCase
133
133
  all_test_tiffs.each do |fname|
134
134
  t = TIFF.new(fname)
135
135
  y = YAML.dump(t)
136
- assert_equal t.to_hash, YAML.load(y).to_hash
136
+ assert_literally_equal t.to_hash, YAML.load(y).to_hash
137
137
  end
138
138
  end
139
+
140
+ def test_jpeg_thumbnails
141
+ count = 0
142
+ all_test_tiffs.each do |fname|
143
+ t = TIFF.new(fname)
144
+ unless t.jpeg_thumbnails.empty?
145
+ assert_nothing_raised do
146
+ t.jpeg_thumbnails.each do |n|
147
+ JPEG.new(StringIO.new(n))
148
+ end
149
+ end
150
+ count += 1
151
+ end
152
+ end
153
+ assert count > 0, 'no thumbnails found'
154
+ end
139
155
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: exifr
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.10.3
7
- date: 2007-10-23 00:00:00 +02:00
6
+ version: 0.10.4
7
+ date: 2007-11-04 00:00:00 +01:00
8
8
  summary: EXIF Reader is a module to read EXIF from JPEG images.
9
9
  require_paths:
10
10
  - lib