exifr 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/exifr/tiff.rb +21 -10
  2. data/tests/jpeg_test.rb +20 -1
  3. metadata +6 -6
data/lib/exifr/tiff.rb CHANGED
@@ -305,23 +305,34 @@ module EXIFR
305
305
  raise MalformedTIFF, "expected [degrees, minutes, seconds]" unless arr.length == 3
306
306
  super
307
307
  end
308
-
308
+
309
309
  def to_f
310
310
  reduce { |m,v| m * 60 + v}.to_f / 3600
311
311
  end
312
312
  end
313
313
 
314
+ def self.rational(n, d)
315
+ Rational.respond_to?(:reduce) ? Rational.reduce(n, d) : 1.quo(d)
316
+ end
317
+
318
+ def self.round(f, n)
319
+ q = (10 ** n)
320
+ (f * q).round.to_f / q
321
+ end
322
+
314
323
  ADAPTERS = Hash.new { proc { |v| v } } # :nodoc:
315
324
  ADAPTERS.merge!({
316
- :date_time_original => time_proc,
317
- :date_time_digitized => time_proc,
318
- :date_time => time_proc,
319
- :orientation => proc { |v| v.map{|v| ORIENTATIONS[v]} },
320
- :gps_latitude => proc { |v| Degrees.new(v) },
321
- :gps_longitude => proc { |v| Degrees.new(v) },
322
- :gps_dest_latitude => proc { |v| Degrees.new(v) },
323
- :gps_dest_longitude => proc { |v| Degrees.new(v) }
324
- })
325
+ :date_time_original => time_proc,
326
+ :date_time_digitized => time_proc,
327
+ :date_time => time_proc,
328
+ :orientation => proc { |v| v.map{|v| ORIENTATIONS[v]} },
329
+ :gps_latitude => proc { |v| Degrees.new(v) },
330
+ :gps_longitude => proc { |v| Degrees.new(v) },
331
+ :gps_dest_latitude => proc { |v| Degrees.new(v) },
332
+ :gps_dest_longitude => proc { |v| Degrees.new(v) },
333
+ :shutter_speed_value => proc { |v| v.map { |v| rational(1, (2 ** v).to_i) } },
334
+ :aperture_value => proc { |v| v.map { |v| round(1.4142 ** v, 1) } }
335
+ })
325
336
 
326
337
  # Names for all recognized TIFF fields.
327
338
  TAGS = ([TAG_MAPPING.keys, TAG_MAPPING.values.map{|v|v.values}].flatten.uniq - IFD_TAGS).map{|v|v.to_s}
data/tests/jpeg_test.rb CHANGED
@@ -18,7 +18,7 @@ class JPEGTest < Test::Unit::TestCase
18
18
  end
19
19
  end
20
20
  end
21
-
21
+
22
22
  def test_raises_malformed_jpeg
23
23
  assert_raise MalformedJPEG do
24
24
  JPEG.new(StringIO.new("djibberish"))
@@ -43,6 +43,24 @@ class JPEGTest < Test::Unit::TestCase
43
43
  assert_equal JPEG.new(f('image.jpg')).comment, "Here's a comment!"
44
44
  end
45
45
 
46
+ def test_shutter_speed_value
47
+ {
48
+ 'canon-g3.exif' => Rational(1, 1244),
49
+ 'Canon_PowerShot_A85.exif' => Rational(1, 806)
50
+ }.each do |file, expected|
51
+ assert_equal expected, TIFF.new(f(file)).shutter_speed_value
52
+ end
53
+ end
54
+
55
+ def test_aperture_value
56
+ {
57
+ 'canon-g3.exif' => 4.5,
58
+ 'Canon_PowerShot_A85.exif' => 2.8
59
+ }.each do |file, expected|
60
+ assert_equal expected, TIFF.new(f(file)).aperture_value
61
+ end
62
+ end
63
+
46
64
  def test_exif
47
65
  assert ! JPEG.new(f('image.jpg')).exif?
48
66
  assert JPEG.new(f('exif.jpg')).exif?
@@ -99,4 +117,5 @@ class JPEGTest < Test::Unit::TestCase
99
117
 
100
118
  assert count > 0, 'no thumbnails found'
101
119
  end
120
+
102
121
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exifr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease: false
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 1
10
- version: 1.1.1
9
+ - 2
10
+ version: 1.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - R.W. van 't Veer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-12 00:00:00 +02:00
18
+ date: 2012-02-20 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  requirements: []
92
92
 
93
93
  rubyforge_project:
94
- rubygems_version: 1.3.7
94
+ rubygems_version: 1.4.2
95
95
  signing_key:
96
96
  specification_version: 3
97
97
  summary: EXIF Reader is a module to read EXIF from JPEG images.