leeh-mini_exiftool 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -0,0 +1,3 @@
1
+ Following files are borrowed from the original Exiftool perl package.
2
+
3
+ Canon.jpg
Binary file
@@ -0,0 +1,106 @@
1
+ [{
2
+ "SourceFile": "test/data/test.jpg",
3
+ "ExifToolVersion": 8.77,
4
+ "FileName": "test.jpg",
5
+ "Directory": "test/data",
6
+ "FileSize": "46 kB",
7
+ "FileModifyDate": "2012:07:05 20:28:24-07:00",
8
+ "FilePermissions": "rw-r--r--",
9
+ "FileType": "JPEG",
10
+ "MIMEType": "image/jpeg",
11
+ "JFIFVersion": 1.01,
12
+ "ExifByteOrder": "Big-endian (Motorola, MM)",
13
+ "ImageDescription": "KONICA MINOLTA DIGITAL CAMERA",
14
+ "Make": "KONICA MINOLTA",
15
+ "Model": "DYNAX 7D",
16
+ "Orientation": "Horizontal (normal)",
17
+ "XResolution": 72,
18
+ "YResolution": 72,
19
+ "ResolutionUnit": "inches",
20
+ "Software": "DYNAX 7D v1.10",
21
+ "ModifyDate": "2005:09:13 20:08:50",
22
+ "YCbCrPositioning": "Centered",
23
+ "ExposureTime": "1/60",
24
+ "FNumber": 9.5,
25
+ "ExposureProgram": "Program AE",
26
+ "ISO": 400,
27
+ "ExifVersion": "0221",
28
+ "DateTimeOriginal": "2005:09:13 20:08:50",
29
+ "CreateDate": "2005:09:13 20:08:50",
30
+ "ComponentsConfiguration": "Y, Cb, Cr, -",
31
+ "BrightnessValue": 4.5,
32
+ "ExposureCompensation": -1,
33
+ "MaxApertureValue": 4.5,
34
+ "MeteringMode": "Multi-segment",
35
+ "LightSource": "Unknown",
36
+ "Flash": "Off, Did not fire",
37
+ "FocalLength": "75.0 mm",
38
+ "SubjectArea": "1504 1000 256 304",
39
+ "MakerNoteVersion": "MLT0",
40
+ "MinoltaImageSize": "Large",
41
+ "WhiteBalance": "Auto",
42
+ "FocusMode": "AF-A",
43
+ "AFPoints": "Center",
44
+ "FlashMode": "Normal",
45
+ "ISOSetting": 400,
46
+ "FreeMemoryCardImages": 202,
47
+ "HueAdjustment": 0,
48
+ "Rotation": "Horizontal (normal)",
49
+ "ImageNumber": 6,
50
+ "NoiseReduction": "Unknown (2)",
51
+ "ImageNumber2": 50,
52
+ "ZoneMatchingOn": "Off",
53
+ "CompressedImageSize": 1598477,
54
+ "PreviewImageStart": 39152,
55
+ "PreviewImageLength": 0,
56
+ "SceneMode": "Standard",
57
+ "ColorMode": "Natural sRGB",
58
+ "MinoltaQuality": "Fine",
59
+ "FlashExposureComp": 0,
60
+ "Teleconverter": "None",
61
+ "ImageStabilization": "On",
62
+ "ZoneMatching": "ISO Setting Used",
63
+ "ColorTemperature": 0,
64
+ "LensType": "Minolta AF 28-135mm F4-4.5 or Sigma Lens",
65
+ "UserComment": "",
66
+ "FlashpixVersion": "0100",
67
+ "ColorSpace": "sRGB",
68
+ "ExifImageWidth": 3008,
69
+ "ExifImageHeight": 2000,
70
+ "CustomRendered": "Normal",
71
+ "ExposureMode": "Auto",
72
+ "DigitalZoomRatio": 0,
73
+ "FocalLengthIn35mmFormat": "112 mm",
74
+ "SceneCaptureType": "Standard",
75
+ "GainControl": "Low gain up",
76
+ "Contrast": "Normal",
77
+ "Saturation": "Normal",
78
+ "Sharpness": "Normal",
79
+ "PrintIMVersion": "0300",
80
+ "Compression": "JPEG (old-style)",
81
+ "ThumbnailOffset": 39274,
82
+ "ThumbnailLength": 1820,
83
+ "CurrentIPTCDigest": "dd8d51d28ddf04f08f870e5ff2f64d01",
84
+ "Keywords": ["Orange","Rot"],
85
+ "ApplicationRecordVersion": 4,
86
+ "SupplementalCategories": "Natur",
87
+ "XMPToolkit": "Image::ExifTool 7.03",
88
+ "Title": "Abenddämmerung",
89
+ "ImageWidth": 300,
90
+ "ImageHeight": 199,
91
+ "EncodingProcess": "Baseline DCT, Huffman coding",
92
+ "BitsPerSample": 8,
93
+ "ColorComponents": 3,
94
+ "YCbCrSubSampling": "YCbCr4:2:0 (2 2)",
95
+ "Aperture": 9.5,
96
+ "ImageSize": "300x199",
97
+ "LensID": "Minolta AF 28-135mm F4-4.5",
98
+ "ScaleFactor35efl": 1.5,
99
+ "ShutterSpeed": "1/60",
100
+ "ThumbnailImage": "(Binary data 1820 bytes)",
101
+ "CircleOfConfusion": "0.020 mm",
102
+ "FOV": "18.3 deg",
103
+ "FocalLength35efl": "75.0 mm (35 mm equivalent: 112.0 mm)",
104
+ "HyperfocalDistance": "29.43 m",
105
+ "LightValue": 10.4
106
+ }]
@@ -0,0 +1,28 @@
1
+ # -- encoding: utf-8 --
2
+ require 'mini_exiftool'
3
+ require 'test/unit'
4
+ require 'fileutils'
5
+ require 'tempfile'
6
+ begin
7
+ require 'turn'
8
+ rescue LoadError
9
+ begin
10
+ require 'rubygems'
11
+ require 'turn'
12
+ rescue LoadError
13
+ end
14
+ end
15
+
16
+ include Test::Unit
17
+
18
+ module TempfileTest
19
+ def setup
20
+ @temp_file = Tempfile.new('test')
21
+ @temp_filename = @temp_file.path
22
+ @data_dir = File.dirname(__FILE__) + '/data'
23
+ end
24
+
25
+ def teardown
26
+ @temp_file.close
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+ # -- encoding: utf-8 --
2
+ require 'helpers_for_test'
3
+
4
+ class TestBadPreviewIFD < TestCase
5
+
6
+ include TempfileTest
7
+
8
+ def setup
9
+ super
10
+ @org_filename = @data_dir + '/Bad_PreviewIFD.jpg'
11
+ FileUtils.cp @org_filename, @temp_filename
12
+ @bad_preview_ifd = MiniExiftool.new @temp_filename
13
+ end
14
+
15
+ # Feature request rubyforge [#29587]
16
+ # Thanks to Michael Grove for reporting
17
+ def test_m_option
18
+ title = 'anything'
19
+ @bad_preview_ifd.title = title
20
+ assert_equal false, @bad_preview_ifd.save, '-m option seems to be not neccessary'
21
+ @bad_preview_ifd.reload
22
+ @bad_preview_ifd.title = title
23
+ @bad_preview_ifd.ignore_minor_errors = true
24
+ assert_equal true, @bad_preview_ifd.save, 'Error while saving'
25
+ @bad_preview_ifd.reload
26
+ assert_equal title, @bad_preview_ifd.title
27
+ end
28
+
29
+ end
@@ -0,0 +1,80 @@
1
+ # -- encoding: utf-8 --
2
+ require 'helpers_for_test'
3
+
4
+ class TestClassMethods < TestCase
5
+
6
+ def test_new
7
+ assert_nothing_raised do
8
+ @mini_exiftool = MiniExiftool.new
9
+ end
10
+ assert_equal nil, @mini_exiftool.filename
11
+ assert_nothing_raised do
12
+ MiniExiftool.new nil
13
+ end
14
+ assert_raises MiniExiftool::Error do
15
+ MiniExiftool.new false
16
+ end
17
+ assert_raises MiniExiftool::Error do
18
+ MiniExiftool.new ''
19
+ end
20
+ assert_raises MiniExiftool::Error do
21
+ MiniExiftool.new 'not_existing_file'
22
+ end
23
+ assert_raises MiniExiftool::Error do
24
+ MiniExiftool.new '.' # directory
25
+ end
26
+ begin
27
+ MiniExiftool.new 'not_existing_file'
28
+ rescue MiniExiftool::Error => e
29
+ assert_match /File 'not_existing_file' does not exist/, e.message
30
+ end
31
+ end
32
+
33
+ def test_command
34
+ cmd = MiniExiftool.command
35
+ assert_equal 'exiftool', cmd
36
+ MiniExiftool.command = 'non_existend'
37
+ assert_equal 'non_existend', MiniExiftool.command
38
+ assert_raises MiniExiftool::Error do
39
+ met = MiniExiftool.new(File.join(File.dirname(__FILE__),
40
+ 'data/test.jpg'))
41
+ end
42
+ MiniExiftool.command = cmd
43
+ end
44
+
45
+ def test_opts
46
+ opts = MiniExiftool.opts
47
+ assert_kind_of Hash, opts
48
+ begin
49
+ org = MiniExiftool.opts[:composite]
50
+ met1 = MiniExiftool.new
51
+ MiniExiftool.opts[:composite] = !org
52
+ met2 = MiniExiftool.new
53
+ MiniExiftool.opts[:composite] = org
54
+ met3 = MiniExiftool.new
55
+ assert_equal org, met1.composite
56
+ assert_equal !org, met2.composite
57
+ assert_equal org, met1.composite
58
+ ensure
59
+ MiniExiftool.opts[:composite] = org
60
+ end
61
+ end
62
+
63
+ def test_all_tags
64
+ all_tags = MiniExiftool.all_tags
65
+ assert all_tags.include?('ISO')
66
+ assert all_tags.include?('OriginalFilename')
67
+ end
68
+
69
+ def test_writable_tags
70
+ w_tags = MiniExiftool.writable_tags
71
+ assert w_tags.include?('ISO')
72
+ assert_equal false, w_tags.include?('xxxxxx')
73
+ end
74
+
75
+ def test_exiftool_version
76
+ v = MiniExiftool.exiftool_version
77
+ assert_match /\A\d+\.\d+\z/, v
78
+ end
79
+
80
+ end
@@ -0,0 +1,19 @@
1
+ # -- encoding: utf-8 --
2
+ require 'helpers_for_test'
3
+
4
+ class TestComposite < TestCase
5
+
6
+ def setup
7
+ @data_dir = File.dirname(__FILE__) + '/data'
8
+ @filename_test = @data_dir + '/test.jpg'
9
+ @mini_exiftool = MiniExiftool.new @filename_test, :composite => false
10
+ @mini_exiftool_c = MiniExiftool.new @filename_test
11
+ end
12
+
13
+ def test_composite_tags
14
+ assert_equal false, @mini_exiftool.tags.include?('Aperture')
15
+ assert_equal true, @mini_exiftool_c.tags.include?('Aperture')
16
+ assert_equal 9.5, @mini_exiftool_c['Aperture']
17
+ end
18
+
19
+ end
@@ -0,0 +1,80 @@
1
+ # -- encoding: utf-8 --
2
+ require 'helpers_for_test'
3
+ require 'yaml'
4
+
5
+ class TestDumping < TestCase
6
+
7
+ def setup
8
+ @data_dir = File.dirname(__FILE__) + '/data'
9
+ @filename_test = @data_dir + '/test.jpg'
10
+ @mini_exiftool = MiniExiftool.new @filename_test
11
+ end
12
+
13
+ def test_to_hash
14
+ hash = @mini_exiftool.to_hash
15
+ assert_equal Hash, hash.class
16
+ assert_equal @mini_exiftool.tags.size, hash.size, 'Size of Hash is not correct.'
17
+ assert_not_nil hash['ExifToolVersion'], 'Original name of exiftool tag is not preserved.'
18
+ all_ok = true
19
+ diffenent_tag = ''
20
+ hash.each do |k,v|
21
+ unless @mini_exiftool[k] == v
22
+ all_ok = false
23
+ diffenent_tag = k
24
+ break
25
+ end
26
+ end
27
+ assert all_ok, "Tag #{diffenent_tag}: expected: #{@mini_exiftool[diffenent_tag]}, actual: v"
28
+ end
29
+
30
+ def test_from_hash
31
+ hash = @mini_exiftool.to_hash
32
+ mini_exiftool_new = MiniExiftool.from_hash hash
33
+ assert_equal MiniExiftool, mini_exiftool_new.class
34
+ assert_equal @mini_exiftool.tags.size, mini_exiftool_new.tags.size
35
+ all_ok = true
36
+ diffenent_tag = ''
37
+ @mini_exiftool.tags.each do |tag|
38
+ unless @mini_exiftool[tag] == mini_exiftool_new[tag]
39
+ all_ok = false
40
+ diffenent_tag = tag
41
+ break
42
+ end
43
+ end
44
+ assert all_ok, "Tag #{diffenent_tag}: expected: #{@mini_exiftool[diffenent_tag]}, actual: #{mini_exiftool_new[diffenent_tag]}"
45
+
46
+ end
47
+
48
+ def test_to_yaml
49
+ hash = @mini_exiftool.to_hash
50
+ yaml = @mini_exiftool.to_yaml
51
+ assert_equal hash, YAML.load(yaml)
52
+ end
53
+
54
+ def test_from_yaml
55
+ hash = @mini_exiftool.to_hash
56
+ yaml = hash.to_yaml
57
+ mini_exiftool_new = MiniExiftool.from_yaml(yaml)
58
+ assert_equal MiniExiftool, mini_exiftool_new.class
59
+ assert_equal hash, mini_exiftool_new.to_hash
60
+ end
61
+
62
+ def test_heuristics_for_restoring_composite
63
+ standard = @mini_exiftool.to_hash
64
+ no_composite = MiniExiftool.new(@filename_test, :composite => false).to_hash
65
+ assert_equal true, MiniExiftool.from_hash(standard).composite
66
+ assert_equal false, MiniExiftool.from_hash(no_composite).composite
67
+ assert_equal true, MiniExiftool.from_yaml(standard.to_yaml).composite
68
+ assert_equal false, MiniExiftool.from_yaml(no_composite.to_yaml).composite
69
+ end
70
+
71
+ def test_heuristics_for_restoring_numerical
72
+ standard = @mini_exiftool.to_hash
73
+ numerical = MiniExiftool.new(@filename_test, :numerical => true).to_hash
74
+ assert_equal false, MiniExiftool.from_hash(standard).numerical
75
+ assert_equal true, MiniExiftool.from_hash(numerical).numerical
76
+ assert_equal false, MiniExiftool.from_yaml(standard.to_yaml).numerical
77
+ assert_equal true, MiniExiftool.from_yaml(numerical.to_yaml).numerical
78
+ end
79
+
80
+ end
@@ -0,0 +1,22 @@
1
+ require 'helpers_for_test'
2
+ require 'json'
3
+
4
+ class TestFromHash < TestCase
5
+ def setup
6
+ @data_dir = File.dirname(__FILE__) + '/data'
7
+ hash_data = JSON.parse(File.read( @data_dir + '/test.jpg.json')).first
8
+ @mini_exiftool = MiniExiftool.from_hash hash_data
9
+ end
10
+
11
+ def test_conversion
12
+ assert_kind_of String, @mini_exiftool.model
13
+ assert_kind_of Time, @mini_exiftool['DateTimeOriginal']
14
+ assert_kind_of Float, @mini_exiftool['MaxApertureValue']
15
+ assert_kind_of String, @mini_exiftool.flash
16
+ assert_kind_of Fixnum, @mini_exiftool['ExposureCompensation']
17
+ assert_kind_of String, (@mini_exiftool['SubjectLocation'] || @mini_exiftool['SubjectArea'])
18
+ assert_kind_of Array, @mini_exiftool['Keywords']
19
+ assert_kind_of String, @mini_exiftool['SupplementalCategories']
20
+ assert_kind_of Rational, @mini_exiftool.shutterspeed
21
+ end
22
+ end
@@ -0,0 +1,53 @@
1
+ # -- encoding: utf-8 --
2
+ require 'helpers_for_test'
3
+
4
+ class TestRead < TestCase
5
+
6
+ def setup
7
+ @data_dir = File.dirname(__FILE__) + '/data'
8
+ @filename_test = @data_dir + '/test.jpg'
9
+ @mini_exiftool = MiniExiftool.new @filename_test
10
+ end
11
+
12
+ def test_access
13
+ assert_equal 'DYNAX 7D', @mini_exiftool['Model']
14
+ assert_equal 'MLT0', @mini_exiftool['maker_note_version']
15
+ assert_equal 'MLT0', @mini_exiftool[:MakerNoteVersion]
16
+ assert_equal 'MLT0', @mini_exiftool[:maker_note_version]
17
+ assert_equal 'MLT0', @mini_exiftool.maker_note_version
18
+ assert_equal 400, @mini_exiftool.iso
19
+ end
20
+
21
+ def test_tags
22
+ assert @mini_exiftool.tags.include?('FileSize')
23
+ end
24
+
25
+ def test_conversion
26
+ assert_kind_of String, @mini_exiftool.model
27
+ assert_kind_of Time, @mini_exiftool['DateTimeOriginal']
28
+ assert_kind_of Float, @mini_exiftool['MaxApertureValue']
29
+ assert_kind_of String, @mini_exiftool.flash
30
+ assert_kind_of Fixnum, @mini_exiftool['ExposureCompensation']
31
+ assert_kind_of String, (@mini_exiftool['SubjectLocation'] || @mini_exiftool['SubjectArea'])
32
+ assert_kind_of Array, @mini_exiftool['Keywords']
33
+ assert_kind_of String, @mini_exiftool['SupplementalCategories']
34
+ assert_kind_of Rational, @mini_exiftool.shutterspeed
35
+ end
36
+
37
+ def test_list_tags
38
+ assert_equal ['Orange', 'Rot'], @mini_exiftool['Keywords']
39
+ assert_equal 'Natur', @mini_exiftool['SupplementalCategories']
40
+ assert_equal ['Natur'], Array(@mini_exiftool['SupplementalCategories'])
41
+ end
42
+
43
+ def test_encoding_conversion
44
+ @mini_exiftool_converted = MiniExiftool.new @filename_test, :convert_encoding => true
45
+ assert_equal 'Abenddämmerung', @mini_exiftool.title
46
+ converted = "Abendd\344mmerung"
47
+ if converted.respond_to?(:force_encoding)
48
+ converted.force_encoding('ISO-8859-1')
49
+ end
50
+ assert_equal converted, @mini_exiftool_converted.title
51
+ end
52
+
53
+ end
@@ -0,0 +1,18 @@
1
+ # -- encoding: utf-8 --
2
+ require 'helpers_for_test'
3
+
4
+ class TestReadCoordinates < TestCase
5
+
6
+ def setup
7
+ @data_dir = File.dirname(__FILE__) + '/data'
8
+ @filename_test = @data_dir + '/test_coordinates.jpg'
9
+ end
10
+
11
+ def test_access_coordinates
12
+ mini_exiftool_coord = MiniExiftool.new @filename_test, :coord_format => "%+.6f"
13
+ assert_equal '+43.653167', mini_exiftool_coord['GPSLatitude']
14
+ assert_equal '-79.373167', mini_exiftool_coord['GPSLongitude']
15
+ assert_equal '+43.653167, -79.373167', mini_exiftool_coord['GPSPosition']
16
+ end
17
+
18
+ end