mini_exiftool 2.8.0 → 2.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b9e96de32763ccdb88cf04f5227edfe743528f2
4
- data.tar.gz: d8d478046af5e4ac9919273f9b8e9e0e6e05d5cb
3
+ metadata.gz: c2559eebe29019af3b0994df1a77e99b5bdea856
4
+ data.tar.gz: 67896c8639c4c237c4943d9aa51aa20598a9c9f2
5
5
  SHA512:
6
- metadata.gz: c554bc5145031425c2369f8eb6ba89c64c469dd223b4d7a70fe98737b8e1a92f1694bd6b46c4172ae7ef6b165e7e0b7898fbaf3e14a0e49b566c094d870071c8
7
- data.tar.gz: c3b5f2b84be63c556a731252fb53107a50692c79867d42c2bf5825d24e7c076aec34ad4069e27b74f66267454ba5c12fb8157eb7ac8f62c5ce4f2eb1075e5f74
6
+ metadata.gz: e73616156d2107208f35f9df53c644b7e8f4c397b4dfbe8af1ff5fe3651ee37c2e3c152c373dc9ce10b73162ea8ee0ba2543c433ebc79d23a0bca7de38fe010a
7
+ data.tar.gz: aec0a216d53f767fc4a1b6d2fc0fab00189a33ae8de4e34474008fd472fc99f152ddd832d17dfef7964864978a60a05c65b17b6f9249d8c17264f004a33afe8c
data/Changelog CHANGED
@@ -1,3 +1,7 @@
1
+ 2.8.1
2
+ - Improve documentation and use Integer instead of Fixnum because it's
3
+ deprecated in Ruby 2.4.0.
4
+
1
5
  2.8.0
2
6
  - MiniExiftool doesn't close any longer a given IO to MiniExiftool.new
3
7
  respectively MiniExiftool#load. You are responsible to do that.
@@ -0,0 +1,181 @@
1
+ # MiniExiftool
2
+
3
+ This library is a wrapper for the ExifTool command-line application
4
+ (http://www.sno.phy.queensu.ca/~phil/exiftool) written by Phil Harvey.
5
+ It provides the full power of ExifTool to Ruby: reading and writing of
6
+ EXIF-data, IPTC-data and XMP-data.
7
+
8
+ ## Requirements
9
+
10
+ Ruby 1.9 or higher and an installation of the ExifTool
11
+ command-line application at least version 7.65.
12
+ If you run on Ruby 1.8 or with a prior exiftool version
13
+ install mini_exiftool version 1.x.x.
14
+ Instructions for installation you can find under
15
+ http://www.sno.phy.queensu.ca/~phil/exiftool/install.html .
16
+
17
+ Alternatively Wil Gieseler has bundled a meta-gem that eliminates the
18
+ need for a separate ExifTool installation. Have a look at
19
+ http://github.com/wilg/mini_exiftool_vendored or
20
+ http://rubygems.org/gems/mini_exiftool_vendored .
21
+
22
+ ## Installation
23
+
24
+ First you need ExifTool (see under Requirements above). Then you can simply
25
+ install the gem with
26
+ ```sh
27
+ gem install mini_exiftool
28
+ ```
29
+ or simply add to the following to your Gemfile:
30
+ ```ruby
31
+ gem 'multi_exiftool'
32
+ ```
33
+
34
+ If you need to support older versions of Ruby or Exiftool (see Requirements above)
35
+
36
+ ```sh
37
+ gem install --version "< 2.0.0" mini_exiftool
38
+ ```
39
+
40
+ or if you use a Gemfile add:
41
+
42
+ ```ruby
43
+ gem 'multi_exiftool', '<2.0.0'
44
+ ```
45
+
46
+ ## Configuration
47
+
48
+ You can manually set the exiftool command that should be used via
49
+
50
+ ```ruby
51
+ MiniExiftool.command = '/path/to/my/exiftool'
52
+ ```
53
+
54
+ In addition, you can also tell MiniExiftool where to store the PStore files with tags
55
+ which exiftool supports. The PStore files are used for performance issues.
56
+ Per default the PStore files are stored in a sub directory `.mini_exiftool` or
57
+ `_mini_exiftool` under your home directory.
58
+
59
+ ```ruby
60
+ MiniExiftool.pstore_dir = '/path/to/pstore/dir'
61
+ ```
62
+
63
+ If you're using Rails, this is easily done with
64
+
65
+ ```ruby
66
+ MiniExiftool.pstore_dir = Rails.root.join('tmp').to_s
67
+ ```
68
+
69
+ Important hint: if you have to change the configuration you have to do this direct
70
+ after `require 'mini_exiftool'`.
71
+
72
+ ## Usage
73
+
74
+ In general MiniExiftool is very intuitive to use as the following examples show:
75
+
76
+ ```ruby
77
+ # Reading meta data from a file
78
+ photo = MiniExiftool.new 'photo.jpg'
79
+ puts photo.title
80
+
81
+ # Alternative reading meta data from an IO instance
82
+ photo = MiniExiftool.new io
83
+ puts photo.title
84
+
85
+ # Writing meta data
86
+ photo = MiniExiftool.new 'photo.jpg'
87
+ photo.title = 'This is the new title'
88
+ photo.save
89
+
90
+ # Copying meta data
91
+ photo = MiniExiftool.new('photo.jpg')
92
+ photo.copy_tags_from('another_photo.jpg', :author)
93
+ ```
94
+
95
+ For further information about using MiniExiftool read the Tutorial.md.
96
+ in the project root folder and have a look at the examples in directory
97
+ examples.
98
+
99
+ ## Caveats
100
+
101
+ The philosophy of MiniExiftool is safety over performance.
102
+ It can not handle more than one file at once. Writing operations are
103
+ executed on a copy of the original file to have atomar writing: Either
104
+ all changed values are written or none.
105
+ To be able to assign errors to a specific tag writing operations also call
106
+ the Exiftool command-line application once for each changed tag!
107
+
108
+ In short: MiniExiftool has a very bad performance especially at write operations.
109
+
110
+ **If you work with many files it is strongly recommended not to use MiniExiftool
111
+ but instead my other gem [MultiExiftool](https://github.com/janfri/multi_exiftool).
112
+ This is designed to handle many files and do reading and writing fast.**
113
+
114
+ ## Encodings
115
+
116
+ In MiniExiftool all strings are encoded in UTF-8. If you need other
117
+ encodings in your project use the String#encod* methods.
118
+
119
+ If you have problems with corrupted strings when using MiniExiftool
120
+ there are two reasons for this:
121
+
122
+ ### Internal character sets
123
+
124
+ You can specify the charset in which the meta data is in the file encoded
125
+ if you read or write to some sections of meta data (i.e. IPTC, XMP ...).
126
+ It exists various options of the form *_encoding: exif, iptc, xmp, png,
127
+ id3, pdf, photoshop, quicktime, aiff, mie and vorbis.
128
+
129
+ For IPTC meta data it is recommended to set also the CodedCharacterSet
130
+ tag.
131
+
132
+ Please read the section about the character sets of the ExifTool command
133
+ line application carefully to understand what's going on
134
+ (http://www.sno.phy.queensu.ca/~phil/exiftool/faq.html#Q10)!
135
+
136
+ ```ruby
137
+ # Using UTF-8 as internal encoding for IPTC tags and MacRoman
138
+ # as internal encoding for EXIF tags
139
+ photo = MiniExiftool.new('photo.jpg', iptc_encoding: 'UTF8',
140
+ exif_encoding: 'MacRoman'
141
+ # IPTC CaptionAbstract is already UTF-8 encoded
142
+ puts photo.caption_abstract
143
+ # EXIF Comment is converted from MacRoman to UTF-8
144
+ puts photo.comment
145
+
146
+ photo = MiniExiftool.new('photo.jpg', iptc_encoding: 'UTF8',
147
+ exif_encoding: 'MacRoman'
148
+ # When saving IPTC data setting CodedCharacterSet as recommended
149
+ photo.coded_character_set = 'UTF8'
150
+ # IPTC CaptionAbstract will be stored in UTF-8 encoding
151
+ photo.caption_abstract = 'Some text with Ümläuts'
152
+ # EXIF Comment will be stored in MacRoman encoding
153
+ photo.comment = 'Comment with Ümläuts'
154
+ photo.save
155
+ ```
156
+
157
+ ### Corrupt characters
158
+
159
+ You use the correct internal character set but in the string are still corrupt
160
+ characters.
161
+ This problem you can solve with the option `replace_invalid_chars`:
162
+
163
+ ```ruby
164
+ # Replace all invalid characters with a question mark
165
+ photo = MiniExiftool.new('photo.jpg', replace_invalid_chars: '?')
166
+ ```
167
+
168
+ ## Contribution
169
+
170
+ The code is hosted in a git repository on github at
171
+ https://github.com/janfri/mini_exiftool
172
+ feel free to contribute!
173
+
174
+ ## Author
175
+ Jan Friedrich <janfri26@gmail.com>
176
+
177
+ ## Copyright / License
178
+ Copyright (c) 2007-2016 by Jan Friedrich
179
+
180
+ Licensed under terms of the GNU LESSER GENERAL PUBLIC LICENSE, Version 2.1,
181
+ February 1999 (see file COPYING for more details)
data/Rakefile CHANGED
@@ -19,7 +19,7 @@ EXIF-data, IPTC-data and XMP-data.
19
19
  END
20
20
  p.homepage = 'https://github.com/janfri/mini_exiftool'
21
21
  p.license = 'LGPL-2.1'
22
- p.gem_files << 'Tutorial.rdoc'
22
+ p.gem_files << 'Tutorial.md'
23
23
  p.gem_files += FileList.new('examples/**')
24
24
  p.install_message = <<-END
25
25
  +-----------------------------------------------------------------------+
@@ -0,0 +1,215 @@
1
+ # Mini Tutorial
2
+
3
+
4
+ ## Installation
5
+
6
+ * Installing the ExifTool command-line application from Phil Harvey
7
+ (see http://www.sno.phy.queensu.ca/~phil/exiftool/install.html)
8
+ * Installing the Ruby library (`gem install mini_exiftool`)
9
+
10
+
11
+ ## Lesson 1: Reading Meta Data
12
+
13
+ ### A Simple Example
14
+
15
+ ```ruby
16
+ require 'mini_exiftool'
17
+
18
+ photo = MiniExiftool.new 'photo.jpg'
19
+ puts photo['DateTimeOriginal']
20
+ ```
21
+
22
+ ### Smart Tag Names
23
+ In the example above we use `photo['DateTimeOriginal']` to
24
+ get the value for the time the photo was taken. But tag names are not
25
+ case sensitive and additional underlines are also irrelevant. So
26
+ following expressions are equivalent:
27
+ ```ruby
28
+ photo['DateTimeOriginal']
29
+ photo['datetimeoriginal']
30
+ photo['date_time_original']
31
+ ```
32
+
33
+ It is also possible to use symbols:
34
+ ```ruby
35
+ photo[:DateTimeOriginal]
36
+ photo[:datetimeoriginal]
37
+ photo[:date_time_original]
38
+ ```
39
+
40
+ ### Nicer Access Via Dynamic Methods
41
+
42
+ Using the []-method is the safest way to access to values of tags
43
+ (e. g. Self-timer you can only access this way) but the smarter way is
44
+ using dynamic method access. You can write:
45
+ ```ruby
46
+ photo.datetimeoriginal
47
+ ```
48
+ or also
49
+ ```ruby
50
+ photo.date_time_original
51
+ ```
52
+
53
+ ### Value Types
54
+
55
+ Following types of values are at the moment supported:
56
+ * Array (e. g. Keywords => ['tree', 'gras'])
57
+ * Integer (e. g. ISO => 400)
58
+ * Float (e. g. FNumber => 9.5)
59
+ * String (e. g. Model => DYNAX 7D)
60
+ * Time (e. g. DateTimeOriginal => 2005:09:13 20:08:50)
61
+
62
+ Be aware, if there is only one value in a tag which can hold multiple
63
+ values the result isn't an array! But you can get one with the Array
64
+ method:
65
+ ```ruby
66
+ # only _one_ keyword
67
+ p1 = MiniExiftool.new 'p1.jpg'
68
+ p1.keywords # => 'red'
69
+ # _more than one_ keywords
70
+ p3 = MiniExiftool.new 'p3.jpg'
71
+ p3.keywords # => ['red', 'yellow', 'green']
72
+
73
+ # if we want to get an array in both cases and don't know
74
+ # if there is one ore more values set let's take Array()
75
+ Array(p1.keywords) # => ['red']
76
+ Array(p3.keywords) # => ['red', 'yellow', 'green']
77
+ ```
78
+
79
+ ### Using options
80
+
81
+ The ExifTool command-line application has an option (-n) to get values
82
+ as numbers if possible, in MiniExiftool you can do this with setting
83
+ the `:numerical` option to `true` while generating a new
84
+ instance with new or using the `numerical=`-method
85
+ combining with calling `reload`.
86
+
87
+ Let's look at an example:
88
+ ```ruby
89
+ # standard: numerical is false
90
+ photo = MiniExiftool.new 'photo.jpg'
91
+ photo.exposure_time # => '1/60 (Rational)
92
+ # now with numerical is true
93
+ photo.numerical = true
94
+ photo.reload
95
+ photo.exposure_time # => 0.01666667 (Float)
96
+ ```
97
+
98
+ This behaviour can be useful if you want to do calculations on the
99
+ value, if you only want to show the value the standard behaviour is
100
+ maybe better.
101
+
102
+ The Time class of Ruby cannot handle timestamps before 1st January 1970
103
+ on some platforms. If there are timestamps in files before this date it
104
+ will result in an error. In this case we can set the option
105
+ `:timestamps` to `DateTime` to use DateTime objects instead
106
+ of Time objects.
107
+
108
+ There is another option `:composite`. If this is set to
109
+ `false` the composite tags are not calculated by the exiftool
110
+ command-line application (option -e).
111
+
112
+ Further options are
113
+ * `:ignore_minor_errors` to ignore minor
114
+ errors (See -m-option of the exiftool command-line application,
115
+ default is `false`)
116
+ * `:coord_format` set format for GPS coordinates (See
117
+ -c-option of the exiftool command-line application, default is `nil`
118
+ that means exiftool standard)
119
+ * `:fast` useful when reading JPEGs over a slow network connection
120
+ (See -fast-option of the exiftool command-line application, default is `false`)
121
+ * `:fast2` useful when reading JPEGs over a slow network connection
122
+ (See -fast2-option of the exiftool command-line application, default is `false`)
123
+ * `:replace_invalid_chars` replace string for invalid
124
+ UTF-8 characters or `false` if no replacing should be done,
125
+ default is `false`
126
+ * `:exif_encoding`, `:iptc_encoding`,
127
+ `:xmp_encoding`, `:png_encoding`,
128
+ `:id3_encoding`, `:pdf_encoding`,
129
+ `:photoshop_encoding`, `:quicktime_encoding`,
130
+ `:aiff_encoding`, `:mie_encoding`,
131
+ `:vorbis_encoding` to set this specific encoding (see
132
+ -charset option of the exiftool command-line application, default is
133
+ `nil`: no encoding specified)
134
+
135
+ ### Using an IO instance
136
+
137
+ ```ruby
138
+ require 'mini_exiftool'
139
+ require 'open3'
140
+
141
+ # Using external curl command
142
+ input, output = Open3.popen2("curl -s http://www.url.of.a.photo")
143
+ input.close
144
+ photo = MiniExiftool.new output
145
+ puts photo['ISO']
146
+ ```
147
+
148
+ The kind of the parameter `filename_or_io` is determined via duck typing:
149
+ if the argument responds to `to_str` it is interpreted as filename, if it
150
+ responds to `read` it is interpreted es IO instance.
151
+ Attention: If you use an IO instance then writing of values is not supported!
152
+
153
+ Look at the show_speedup_with_fast_option example in the MiniExiftool examples
154
+ directory for more details about using an IO instance.
155
+
156
+
157
+ ## Lesson 2: Writing Meta Data
158
+
159
+ ### Also A Very Simple Example
160
+
161
+ ```ruby
162
+ require 'mini_exiftool'
163
+
164
+ photo = MiniExiftool.new 'photo.jpg'
165
+ photo.comment = 'hello world'
166
+ photo.save
167
+ ```
168
+
169
+
170
+ ### Save Is Atomar
171
+
172
+ If you have changed several values and call the `save`-method either
173
+ all changes will be written to the file or nothing. The return value
174
+ of the `save`-method is `true` if all values are written to the file
175
+ otherwise save returns `false`. In the last case you can use the
176
+ `errors`-method which returns a hash of the tags which values couldn't
177
+ be written with an error message for each of them.
178
+
179
+
180
+ ### Interesting Methods
181
+
182
+ Have a look at the `changed?`-method for checking if the
183
+ value of a specific tag is changed or a changing in general is
184
+ done. In the same way the `revert`-method reverts the value of a
185
+ specific tag or in general all changes.
186
+
187
+ You should also look at the rdoc information of MiniExiftool.
188
+
189
+
190
+ ## Lesson 3: Copying Meta Data
191
+
192
+ ### Examples
193
+
194
+ ```ruby
195
+ require 'mini_exiftool'
196
+
197
+ photo = MiniExiftool.new('photo.jpg')
198
+
199
+ # Update the author tag of photo.jpg with the value of the author tag
200
+ # of another_photo.jpg
201
+ photo.copy_tags_from('another_photo.jpg', 'Author')
202
+
203
+ # It's also possible to use symbols and case is also not meaningful
204
+ photo.copy_tags_from('another_photo.jpg', :author)
205
+
206
+ # Further more than one tag can be copied at once
207
+ photo.copy_tags_from('another_photo', %w[author copyright])
208
+ ```
209
+
210
+ Look at the file copy_icc_profile.rb in the examples folder of MiniExiftool.
211
+
212
+
213
+ ## Further Examples
214
+
215
+ Have a look in the examples folder of MiniExiftool.
@@ -26,7 +26,7 @@ require 'time'
26
26
  # Simple OO access to the ExifTool command-line application.
27
27
  class MiniExiftool
28
28
 
29
- VERSION = '2.8.0'
29
+ VERSION = '2.8.1'
30
30
 
31
31
  # Name of the ExifTool command-line application
32
32
  @@cmd = 'exiftool'
@@ -13,7 +13,7 @@ class TestFromHash < TestCase
13
13
  assert_kind_of Time, @mini_exiftool['DateTimeOriginal']
14
14
  assert_kind_of Float, @mini_exiftool['MaxApertureValue']
15
15
  assert_kind_of String, @mini_exiftool.flash
16
- assert_kind_of Fixnum, @mini_exiftool['ExposureCompensation']
16
+ assert_kind_of Integer, @mini_exiftool['ExposureCompensation']
17
17
  assert_kind_of String, (@mini_exiftool['SubjectLocation'] || @mini_exiftool['SubjectArea'])
18
18
  assert_kind_of Array, @mini_exiftool['Keywords']
19
19
  assert_kind_of String, @mini_exiftool['SupplementalCategories']
@@ -27,7 +27,7 @@ class TestRead < TestCase
27
27
  assert_kind_of Time, @mini_exiftool['DateTimeOriginal']
28
28
  assert_kind_of Float, @mini_exiftool['MaxApertureValue']
29
29
  assert_kind_of String, @mini_exiftool.flash
30
- assert_kind_of Fixnum, @mini_exiftool['ExposureCompensation']
30
+ assert_kind_of Integer, @mini_exiftool['ExposureCompensation']
31
31
  assert_kind_of String, (@mini_exiftool['SubjectLocation'] || @mini_exiftool['SubjectArea'])
32
32
  assert_kind_of Array, @mini_exiftool['Keywords']
33
33
  assert_kind_of String, @mini_exiftool['SupplementalCategories']
@@ -22,9 +22,9 @@ class TestReadNumerical < TestCase
22
22
  assert_kind_of String, @mini_exiftool_num.model
23
23
  assert_kind_of Time, @mini_exiftool_num['DateTimeOriginal']
24
24
  assert_kind_of Float, @mini_exiftool_num['MaxApertureValue']
25
- assert_kind_of Fixnum, @mini_exiftool_num.flash
25
+ assert_kind_of Integer, @mini_exiftool_num.flash
26
26
  assert_kind_of String, @mini_exiftool_num.exif_version
27
- assert_kind_of Fixnum, @mini_exiftool_num['ExposureCompensation']
27
+ assert_kind_of Integer, @mini_exiftool_num['ExposureCompensation']
28
28
  assert_kind_of String, (@mini_exiftool_num['SubjectLocation'] || @mini_exiftool_num['SubjectArea'])
29
29
  assert_kind_of Array, @mini_exiftool_num['Keywords']
30
30
  assert_kind_of String, @mini_exiftool_num['SupplementalCategories']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_exiftool
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 2.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Friedrich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-12 00:00:00.000000000 Z
11
+ date: 2017-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rim
@@ -78,9 +78,9 @@ extra_rdoc_files: []
78
78
  files:
79
79
  - COPYING
80
80
  - Changelog
81
- - README.rdoc
81
+ - README.md
82
82
  - Rakefile
83
- - Tutorial.rdoc
83
+ - Tutorial.md
84
84
  - examples/copy_icc_profile.rb
85
85
  - examples/external_photo.rb
86
86
  - examples/print_portraits.rb
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  version: '0'
147
147
  requirements: []
148
148
  rubyforge_project:
149
- rubygems_version: 2.6.6
149
+ rubygems_version: 2.6.12
150
150
  signing_key:
151
151
  specification_version: 4
152
152
  summary: This library is a wrapper for the ExifTool command-line application (http://www.sno.phy.queensu.ca/~phil/exiftool).
@@ -1,137 +0,0 @@
1
- = MiniExiftool
2
-
3
- This library is a wrapper for the ExifTool command-line application
4
- (http://www.sno.phy.queensu.ca/~phil/exiftool) written by Phil Harvey.
5
- It provides the full power of ExifTool to Ruby: reading and writing of
6
- EXIF-data, IPTC-data and XMP-data.
7
-
8
- == Requirements
9
-
10
- Ruby 1.9 or higher and an installation of the ExifTool
11
- command-line application at least version 7.65.
12
- If you run on Ruby 1.8 or with a prior exiftool version
13
- install mini_exiftool version 1.x.x.
14
- Instructions for installation you can find under
15
- http://www.sno.phy.queensu.ca/~phil/exiftool/install.html .
16
-
17
- Alternatively Wil Gieseler has bundled a meta-gem that eliminates the
18
- need for a separate ExifTool installation. Have a look at
19
- http://github.com/wilg/mini_exiftool_vendored or
20
- http://rubygems.org/gems/mini_exiftool_vendored .
21
-
22
- == Installation
23
-
24
- First you need ExifTool (see under Requirements above). Then you can simply
25
- install the gem with
26
- gem install mini_exiftool
27
-
28
- If you need to support older versions of Ruby or exiftool (see Requirements above)
29
- gem install --version "< 2.0.0" mini_exiftool
30
-
31
- == Configuration
32
-
33
- You can manually set the exiftool command that should be used via
34
- MiniExiftool.command = '/path/to/my/exiftool'
35
-
36
- In addition, you can also tell MiniExiftool where to store the PStore files with tags
37
- which exiftool supports. The PStore files are used for performance issues.
38
- Per default the PStore files are stored in a sub directory .mini_exiftool or
39
- _mini_exiftool under your home directory.
40
- MiniExiftool.pstore_dir = '/path/to/pstore/dir'
41
-
42
- If you're using Rails, this is easily done with
43
- MiniExiftool.pstore_dir = Rails.root.join('tmp').to_s
44
-
45
- Important hint: if you have to change the configuration you have to do this direct
46
- after require 'mini_exiftool'.
47
-
48
- == Usage
49
-
50
- In general MiniExiftool is very intuitive to use as the following examples show:
51
-
52
- # Reading meta data from a file
53
- photo = MiniExiftool.new 'photo.jpg'
54
- puts photo.title
55
-
56
- # Alternative reading meta data from an IO instance
57
- photo = MiniExiftool.new io
58
- puts photo.title
59
-
60
- # Writing meta data
61
- photo = MiniExiftool.new 'photo.jpg'
62
- photo.title = 'This is the new title'
63
- photo.save
64
-
65
- # Copying meta data
66
- photo = MiniExiftool.new('photo.jpg')
67
- photo.copy_tags_from('another_photo.jpg', :author)
68
-
69
-
70
- For further information about using MiniExiftool read the Tutorial.rdoc
71
- in the project root folder and have a look at the examples in directory
72
- examples.
73
-
74
- == Encodings
75
-
76
- In MiniExiftool all strings are encoded in UTF-8. If you need other
77
- encodings in your project use the String#encod* methods.
78
-
79
- If you have problems with corrupted strings when using MiniExiftool
80
- there are two reasons for this:
81
-
82
- === Internal character sets
83
-
84
- You can specify the charset in which the meta data is in the file encoded
85
- if you read or write to some sections of meta data (i.e. IPTC, XMP ...).
86
- It exists various options of the form *_encoding: exif, iptc, xmp, png,
87
- id3, pdf, photoshop, quicktime, aiff, mie and vorbis.
88
-
89
- For IPTC meta data it is recommended to set also the CodedCharacterSet
90
- tag.
91
-
92
- Please read the section about the character sets of the ExifTool command
93
- line application carefully to understand what's going on
94
- (http://www.sno.phy.queensu.ca/~phil/exiftool/faq.html#Q10)!
95
-
96
- # Using UTF-8 as internal encoding for IPTC tags and MacRoman
97
- # as internal encoding for EXIF tags
98
- photo = MiniExiftool.new('photo.jpg', iptc_encoding: 'UTF8',
99
- exif_encoding: 'MacRoman'
100
- # IPTC CaptionAbstract is already UTF-8 encoded
101
- puts photo.caption_abstract
102
- # EXIF Comment is converted from MacRoman to UTF-8
103
- puts photo.comment
104
-
105
- photo = MiniExiftool.new('photo.jpg', iptc_encoding: 'UTF8',
106
- exif_encoding: 'MacRoman'
107
- # When saving IPTC data setting CodedCharacterSet as recommended
108
- photo.coded_character_set = 'UTF8'
109
- # IPTC CaptionAbstract will be stored in UTF-8 encoding
110
- photo.caption_abstract = 'Some text with Ümläuts'
111
- # EXIF Comment will be stored in MacRoman encoding
112
- photo.comment = 'Comment with Ümläuts'
113
- photo.save
114
-
115
- === Corrupt characters
116
-
117
- You use the correct internal character set but in the string are still corrupt
118
- characters.
119
- This problem you can solve with the option replace_invalid_chars:
120
-
121
- # Replace all invalid characters with a question mark
122
- photo = MiniExiftool.new('photo.jpg', replace_invalid_chars: '?')
123
-
124
- == Contribution
125
-
126
- The code is hosted in a git repository on github at
127
- https://github.com/janfri/mini_exiftool
128
- feel free to contribute!
129
-
130
- == Author
131
- Jan Friedrich <janfri26@gmail.com>
132
-
133
- == Copyright / License
134
- Copyright (c) 2007-2016 by Jan Friedrich
135
-
136
- Licensed under terms of the GNU LESSER GENERAL PUBLIC LICENSE, Version 2.1,
137
- February 1999 (see file COPYING for more details)
@@ -1,194 +0,0 @@
1
- = Mini Tutorial
2
-
3
-
4
- == Installation
5
-
6
- * Installing the ExifTool command-line application from Phil Harvey
7
- (see http://www.sno.phy.queensu.ca/~phil/exiftool/install.html)
8
- * Installing the Ruby library (<code>gem install mini_exiftool</code>)
9
-
10
-
11
- == Lesson 1: Reading Meta Data
12
-
13
- === A Simple Example
14
-
15
- require 'mini_exiftool'
16
-
17
- photo = MiniExiftool.new 'photo.jpg'
18
- puts photo['DateTimeOriginal']
19
-
20
- === Smart Tag Names
21
- In the example above we use <code>photo['DateTimeOriginal']</code> to
22
- get the value for the time the photo was taken. But tag names are not
23
- case sensitive and additional underlines are also irrelevant. So
24
- following expressions are equivalent:
25
- photo['DateTimeOriginal']
26
- photo['datetimeoriginal']
27
- photo['date_time_original']
28
-
29
- It is also possible to use symbols:
30
- photo[:DateTimeOriginal]
31
- photo[:datetimeoriginal]
32
- photo[:date_time_original]
33
-
34
- === Nicer Access Via Dynamic Methods
35
-
36
- Using the []-method is the safest way to access to values of tags
37
- (e. g. Self-timer you can only access this way) but the smarter way is
38
- using dynamic method access. You can write:
39
- photo.datetimeoriginal
40
- or also
41
- photo.date_time_original
42
-
43
- === Value Types
44
-
45
- Following types of values are at the moment supported:
46
- * Array (e. g. Keywords => ['tree', 'gras'])
47
- * Fixnum (e. g. ISO => 400)
48
- * Float (e. g. FNumber => 9.5)
49
- * String (e. g. Model => DYNAX 7D)
50
- * Time (e. g. DateTimeOriginal => 2005:09:13 20:08:50)
51
-
52
- Be aware, if there is only one value in a tag which can hold multiple
53
- values the result isn't an array! But you can get one with the Array
54
- method:
55
- # only _one_ keyword
56
- p1 = MiniExiftool.new 'p1.jpg'
57
- p1.keywords # => 'red'
58
- # _more than one_ keywords
59
- p3 = MiniExiftool.new 'p3.jpg'
60
- p3.keywords # => ['red', 'yellow', 'green']
61
-
62
- # if we want to get an array in both cases and don't know
63
- # if there is one ore more values set let's take Array()
64
- Array(p1.keywords) # => ['red']
65
- Array(p3.keywords) # => ['red', 'yellow', 'green']
66
-
67
- === Using options
68
-
69
- The ExifTool command-line application has an option (-n) to get values
70
- as numbers if possible, in MiniExiftool you can do this with setting
71
- the <code>:numerical</code> option to +true+ while generating a new
72
- instance with new or using the <code>numerical=</code>-method
73
- combining with calling <code>reload</code>.
74
-
75
- Let's look at an example:
76
- # standard: numerical is false
77
- photo = MiniExiftool.new 'photo.jpg'
78
- photo.exposure_time # => '1/60' (String)
79
- # now with numerical is true
80
- photo.numerical = true
81
- photo.reload
82
- photo.exposure_time # => 0.01666667 (Float)
83
- This behaviour can be useful if you want to do calculations on the
84
- value, if you only want to show the value the standard behaviour is
85
- maybe better.
86
-
87
- The Time class of Ruby cannot handle timestamps before 1st January 1970
88
- on some platforms. If there are timestamps in files before this date it
89
- will result in an error. In this case we can set the option
90
- <code>:timestamps</code> to +DateTime+ to use DateTime objects instead
91
- of Time objects.
92
-
93
- There is another option <code>:composite</code>. If this is set to
94
- +false+ the composite tags are not calculated by the exiftool
95
- command-line application (option -e).
96
-
97
- Further options are
98
- * <code>:ignore_minor_errors</code> to ignore minor
99
- errors (See -m-option of the exiftool command-line application,
100
- default is +false+)
101
- * <code>:coord_format</code> set format for GPS coordinates (See
102
- -c-option of the exiftool command-line application, default is +nil+
103
- that means exiftool standard)
104
- * <code>:fast</code> useful when reading JPEGs over a slow network connection
105
- (See -fast-option of the exiftool command-line application, default is +false+)
106
- * <code>:fast2</code> useful when reading JPEGs over a slow network connection
107
- (See -fast2-option of the exiftool command-line application, default is +false+)
108
- * <code>:replace_invalid_chars</code> replace string for invalid
109
- UTF-8 characters or +false+ if no replacing should be done,
110
- default is +false+
111
- * <code>:exif_encoding</code>, <code>:iptc_encoding</code>,
112
- <code>:xmp_encoding</code>, <code>:png_encoding</code>,
113
- <code>:id3_encoding</code>, <code>:pdf_encoding</code>,
114
- <code>:photoshop_encoding</code>, <code>:quicktime_encoding</code>,
115
- <code>:aiff_encoding</code>, <code>:mie_encoding</code>,
116
- <code>:vorbis_encoding</code> to set this specific encoding (see
117
- -charset option of the exiftool command-line application, default is
118
- +nil+: no encoding specified)
119
-
120
- === Using an IO instance
121
-
122
- require 'mini_exiftool'
123
- require 'open3'
124
-
125
- # Using external curl command
126
- input, output = Open3.popen2("curl -s http://www.url.of.a.photo")
127
- input.close
128
- photo = MiniExiftool.new output
129
- puts photo['ISO']
130
-
131
- The kind of the parameter +filename_or_io+ is determined via duck typing:
132
- if the argument responds to +to_str+ it is interpreted as filename, if it
133
- responds to +read+ it is interpreted es IO instance.
134
- Attention: If you use an IO instance then writing of values is not supported!
135
-
136
- Look at the show_speedup_with_fast_option example in the MiniExiftool examples
137
- directory for more details about using an IO instance.
138
-
139
-
140
- == Lesson 2: Writing Meta Data
141
-
142
- === Also A Very Simple Example
143
-
144
- require 'mini_exiftool'
145
-
146
- photo = MiniExiftool.new 'photo.jpg'
147
- photo.comment = 'hello world'
148
- photo.save
149
-
150
-
151
- === Save Is Atomar
152
-
153
- If you have changed several values and call the +save+-method either
154
- all changes will be written to the file or nothing. The return value
155
- of the +save+-method is +true+ if all values are written to the file
156
- otherwise save returns +false+. In the last case you can use the
157
- +errors+-method which returns a hash of the tags which values couldn't
158
- be written with an error message for each of them.
159
-
160
-
161
- === Interesting Methods
162
-
163
- Have a look at the <code>changed?</code>-method for checking if the
164
- value of a specific tag is changed or a changing in general is
165
- done. In the same way the +revert+-method reverts the value of a
166
- specific tag or in general all changes.
167
-
168
- You should also look at the rdoc information of MiniExiftool.
169
-
170
-
171
- == Lesson 3: Copying Meta Data
172
-
173
- === Examples
174
-
175
- require 'mini_exiftool'
176
-
177
- photo = MiniExiftool.new('photo.jpg')
178
-
179
- # Update the author tag of photo.jpg with the value of the author tag
180
- # of another_photo.jpg
181
- photo.copy_tags_from('another_photo.jpg', 'Author')
182
-
183
- # It's also possible to use symbols and case is also not meaningful
184
- photo.copy_tags_from('another_photo.jpg', :author)
185
-
186
- # Further more than one tag can be copied at once
187
- photo.copy_tags_from('another_photo', %w[author copyright])
188
-
189
- Look at the file copy_icc_profile.rb in the examples folder of MiniExiftool.
190
-
191
-
192
- == Further Examples
193
-
194
- Have a look in the examples folder of MiniExiftool.