micro_magick 1.0.1 → 1.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10a457128480449b93b16c01a2be37a44de681a5
4
- data.tar.gz: 9e6fac256930e94e810c9ac5d80d6e1946943bd1
3
+ metadata.gz: 7db109b6f15512b98ddf6a0636105ffc2230909d
4
+ data.tar.gz: e462ef989de13f415ff76e33ec21949920272b2d
5
5
  SHA512:
6
- metadata.gz: 43856ed019ecae1569a17fbdffec70d61e85060e858f0c5b43da9854e149df9716561435bb115b1d5d54b0c024d5edc7adae75706752f64b74d21b34d40d460a
7
- data.tar.gz: a463a2c9c7b1c1774479a4aef04df80c791c90dfe12a793984a4d2a36370ac9c1c720bf8594b58a583055cc2e61baa041cae03c909ad2d232d8524d3d53e9b98
6
+ metadata.gz: c069a6361739fd6989779e5c286750e33392ef5d039e5f214da27428d94d861187dd58010fa1c5d92b2c8a3c7a08102363c75b2c05072bc688c74ce1914a7b2e
7
+ data.tar.gz: 2ea92b82fba3b5752bfbf4de96a8527e4b40fc7005010d4969d69ed586555f6ebae4942fa196c26dabef6675b611e59703cc951a6008364e0457c728a4214e80
@@ -66,7 +66,7 @@ module MicroMagick
66
66
  if err.size > 0 || status != 0
67
67
  error = if err =~ /unrecognized option/i
68
68
  ArgumentError
69
- elsif err =~ /corrupt/i
69
+ elsif err =~ /corrupt|CRC error/i
70
70
  CorruptImageError
71
71
  elsif err =~ /no such file or directory|unable to open/i
72
72
  NoSuchFile
@@ -9,6 +9,25 @@ module MicroMagick
9
9
  @input_file = input_file
10
10
  @input_options = []
11
11
  @output_options = []
12
+ @identify = nil
13
+ end
14
+
15
+ # If you need to add an option that affects processing of input files,
16
+ # you can use this method.
17
+ def add_input_option(option_name, *args)
18
+ (@input_options ||= []).push(option_name)
19
+ args.each { |ea| @input_options.push(Shellwords.escape(ea.to_s)) }
20
+
21
+ # Support call chaining:
22
+ self
23
+ end
24
+
25
+ # Ignore the checksum embedded in the image.
26
+ # Useful if the image is known to not be corrupted but has an invalid checksum;
27
+ # some devices export such broken images.
28
+ def ignore_checksum
29
+ # Only PNG for now
30
+ add_input_option("-define", "png:ignore-crc")
12
31
  end
13
32
 
14
33
  def width
@@ -87,9 +106,9 @@ module MicroMagick
87
106
 
88
107
  def command(command_name, output_file = nil)
89
108
  cmd = [command_name]
90
- cmd.push *@input_options
91
- cmd.push Shellwords.escape(@input_file)
92
- cmd.push *@output_options
109
+ cmd.push(*@input_options)
110
+ cmd.push(Shellwords.escape(@input_file))
111
+ cmd.push(*@output_options)
93
112
  cmd.push(Shellwords.escape(output_file)) if output_file
94
113
  cmd
95
114
  end
@@ -99,7 +118,7 @@ module MicroMagick
99
118
  cmd = ['identify', '-verbose', '-format', '%wx%h', Shellwords.escape(input_file)]
100
119
  @identify = IdentifyParser.new(MicroMagick.exec(cmd, true))
101
120
  @corrupt = false
102
- rescue CorruptImageError => e
121
+ rescue CorruptImageError
103
122
  @identify = {}
104
123
  @corrupt = true
105
124
  end
@@ -1,3 +1,3 @@
1
1
  module MicroMagick
2
- VERSION = Gem::Version.new('1.0.1')
2
+ VERSION = Gem::Version.new('1.1.0')
3
3
  end
Binary file
@@ -19,18 +19,15 @@ module ImageTests
19
19
  img.corrupt?.must_be_false
20
20
  end
21
21
 
22
- def corrupt_checks_broken
23
- MicroMagick.imagemagick? && MicroMagick.version < Gem::Version.new('6.7.0')
22
+ def old_imagemagick
23
+ MicroMagick.imagemagick? && MicroMagick.version < Gem::Version.new('6.8.0')
24
24
  end
25
25
 
26
26
  it 'detects corrupt images properly' do
27
- if corrupt_checks_broken
28
- puts "skipping .corrupt? tests"
29
- else
30
- corrupt.width.must_be_nil
31
- corrupt.height.must_be_nil
32
- corrupt.corrupt?.must_be_true
33
- end
27
+ skip "Old ImageMagick versions don't detect corruption properly" if old_imagemagick
28
+ corrupt.width.must_be_nil
29
+ corrupt.height.must_be_nil
30
+ corrupt.corrupt?.must_be_true
34
31
  end
35
32
 
36
33
  it 'extracts image geometry for problematic JPGs' do
@@ -84,6 +81,18 @@ module ImageTests
84
81
  proc { img.write(outfile) }.must_raise MicroMagick::ArgumentError
85
82
  end
86
83
 
84
+ it 'allows to ignore checksum errors' do
85
+ unless MicroMagick.imagemagick? && MicroMagick.version >= Gem::Version.new('7.0.6')
86
+ skip "The png:ignore-crc format option only exists in ImageMagick 7.0.6+"
87
+ end
88
+
89
+ img = MicroMagick::Image.new('test/broken_crc.png')
90
+ proc { img.write(outfile) }.must_raise MicroMagick::CorruptImageError
91
+
92
+ img = MicroMagick::Image.new('test/broken_crc.png')
93
+ img.ignore_checksum.write(outfile)
94
+ end
95
+
87
96
  let(:enoent) { MicroMagick::Image.new('nonexistant-file.jpg') }
88
97
 
89
98
  it 'raises NoSuchFile when fetching attributes' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: micro_magick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew McEachen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-07 00:00:00.000000000 Z
11
+ date: 2017-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -95,6 +95,7 @@ files:
95
95
  - test/480x270.jpg
96
96
  - test/bad_exif.jpg
97
97
  - test/borked.jpg
98
+ - test/broken_crc.png
98
99
  - test/image_tests.rb
99
100
  - test/micro_gmagick_test.rb
100
101
  - test/micro_imagick_test.rb
@@ -120,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
121
  version: '0'
121
122
  requirements: []
122
123
  rubyforge_project:
123
- rubygems_version: 2.4.5.1
124
+ rubygems_version: 2.6.8
124
125
  signing_key:
125
126
  specification_version: 4
126
127
  summary: Simple and efficient ImageMagick/GraphicsMagick ruby wrapper
@@ -129,9 +130,9 @@ test_files:
129
130
  - test/480x270.jpg
130
131
  - test/bad_exif.jpg
131
132
  - test/borked.jpg
133
+ - test/broken_crc.png
132
134
  - test/image_tests.rb
133
135
  - test/micro_gmagick_test.rb
134
136
  - test/micro_imagick_test.rb
135
137
  - test/micro_magick_test.rb
136
138
  - test/test_helper.rb
137
- has_rdoc: