Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support -m option of the exiftool command-line application.

  • Loading branch information...
commit f218515ed5d9139aa5b5ca05f83c9e2ec02bd1a0 1 parent 70eb911
janfri authored
10 lib/mini_exiftool.rb
View
@@ -27,10 +27,10 @@ class MiniExiftool
@@cmd = 'exiftool'
# Hash of the standard options used when call MiniExiftool.new
- @@opts = { :numerical => false, :composite => true, :convert_encoding => false, :timestamps => Time }
+ @@opts = { :numerical => false, :composite => true, :convert_encoding => false, :ignore_minor_errors => false, :timestamps => Time }
attr_reader :filename
- attr_accessor :numerical, :composite, :convert_encoding, :errors, :timestamps
+ attr_accessor :numerical, :composite, :convert_encoding, :ignore_minor_errors, :errors, :timestamps
VERSION = '1.4.4'
@@ -39,7 +39,9 @@ class MiniExiftool
# * <code>:composite</code> for including composite tags while loading,
# default is +true+
# * <code>:convert_encoding</code> convert encoding (See -L-option of
- # the exiftool command-line application, default is +false+
+ # the exiftool command-line application, default is +false+)
+ # * <code>:ignore_minor_errors</code> ignore minor errors (See -m-option
+ # of the exiftool command-line application, default is +false+)
# * <code>:timestamps</code> generating DateTime objects instead of
# Time objects if set to <code>DateTime</code>, default is +Time+
#
@@ -51,6 +53,7 @@ def initialize filename=nil, opts={}
@numerical = opts[:numerical]
@composite = opts[:composite]
@convert_encoding = opts[:convert_encoding]
+ @ignore_minor_errors = opts[:ignore_minor_errors]
@timestamps = opts[:timestamps]
@values = TagHash.new
@tag_names = TagHash.new
@@ -159,6 +162,7 @@ def save
opt_params = ''
opt_params << (arr_val.detect {|x| x.kind_of?(Numeric)} ? '-n ' : '')
opt_params << (@convert_encoding ? '-L ' : '')
+ opt_params << (@ignore_minor_errors ? '-m' : '')
cmd = %Q(#@@cmd -q -P -overwrite_original #{opt_params} #{tag_params} #{temp_filename})
if convert_encoding && cmd.respond_to?(:encode)
cmd.encode('ISO-8859-1')
BIN  test/data/Bad_PreviewIFD.jpg
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 test/test_bad_preview_ifd.rb
View
@@ -0,0 +1,29 @@
+# -- encoding: utf-8 --
+require 'helpers_for_test'
+
+class TestBadPreviewIFD < TestCase
+
+ include TempfileTest
+
+ def setup
+ super
+ @org_filename = @data_dir + '/Bad_PreviewIFD.jpg'
+ FileUtils.cp @org_filename, @temp_filename
+ @bad_preview_ifd = MiniExiftool.new @temp_filename
+ end
+
+ # Feature request rubyforge [#29587]
+ # Thanks to Michael Grove for reporting
+ def test_m_option
+ title = 'anything'
+ @bad_preview_ifd.title = title
+ assert_equal false, @bad_preview_ifd.save, '-m option seems to be not neccessary'
+ @bad_preview_ifd.reload
+ @bad_preview_ifd.title = title
+ @bad_preview_ifd.ignore_minor_errors = true
+ assert_equal true, @bad_preview_ifd.save, 'Error while saving'
+ @bad_preview_ifd.reload
+ assert_equal title, @bad_preview_ifd.title
+ end
+
+end
2  test/test_write.rb
View
@@ -90,7 +90,7 @@ def test_time_conversion
def test_float_conversion
assert_kind_of Float, @mini_exiftool_num['BrightnessValue']
- new_time = @mini_exiftool_num['BrightnessValue'] + 1
+ new_time = @mini_exiftool_num['BrightnessValue'] + 1
@mini_exiftool_num['BrightnessValue'] = new_time
assert_equal new_time, @mini_exiftool_num['BrightnessValue']
assert_equal true, @mini_exiftool_num.changed_tags.include?('BrightnessValue')
Please sign in to comment.
Something went wrong with that request. Please try again.