mork 0.18.1 → 0.18.2

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
  SHA256:
3
- metadata.gz: 9c871eb798a14173c833892d6cb6030e266158239058f9ef0fbb2ff359c1073f
4
- data.tar.gz: 8e2ac94ee3e806455d617f959459eebe6964521c9711064e5f0c86facf9fda8f
3
+ metadata.gz: 8cdb6af94ff682ccad23d669fb624d263ea4fb28d5911e3ada2ceeb200c8fd4a
4
+ data.tar.gz: 956342c055f892ee7e4c44187711b3660eefd8fcee68723bfd1cb2fb245d0a75
5
5
  SHA512:
6
- metadata.gz: 464bb64cfe62e30bba0037b154d527a00d165b1bd71b4ffa4534bc28cace42fd86aa8455d927d6d660c218d25be92cca4292f60aa66b787af8ce9ed7bea82ba9
7
- data.tar.gz: 37ab32c16c165c6c120a8addca74a6bafbe44a02d494ab80968a499dd5d44bad1b6402031c3ff8703a94b8ffbcdd8fc6afd093369b9535883aa49aa2ff2dd0e3
6
+ metadata.gz: 0c75eaac5ad245b5c86dde97f7e68c43a08486c248014e27963c8c1f763b2cc14fbe545d13f1d75675f1367daaf11df05f8109fdf88d752324cf7972a560e9e4
7
+ data.tar.gz: 8864848f8f6a4a9cada44dd6f74183928fcdbf15986c97a27eb4d95ba6f60f2c9f0dd6a95ec8029fe961df0f4289da21703e8b9472c4ba6ad3f70929c043ffeb
data/lib/mork/magicko.rb CHANGED
@@ -18,7 +18,11 @@ module Mork
18
18
  # a default of 150 dpi seems sensible. It should not affect bitmaps.
19
19
  density = 150
20
20
  # inspect the source file
21
- s1, s2, s3 = Open3.capture3 "identify -density #{density} -format '%w %h %m' #{path}"
21
+ identify = MiniMagick.identify
22
+ identify.density density
23
+ identify.format '%w %h %m'
24
+ identify << path
25
+ s1, s2, s3 = Open3.capture3(*identify.command)
22
26
  if s3.success?
23
27
  # parse the identify command output
24
28
  w, h, @type = s1.split(' ')
@@ -54,16 +58,17 @@ module Mork
54
58
  # (i.e. the centers of the four registration marks)
55
59
  # pp: a hash in the form of pp[:tl][:x], pp[:tl][:y], etc.
56
60
  def registered_bytes(pp)
57
- read_bytes "-distort Perspective '#{pps pp}'"
61
+ read_bytes '-distort', 'Perspective', pps(pp)
58
62
  end
59
63
 
60
64
  # Reading from the image file the bytes from one of the four corner
61
65
  # squares encompassing each registration mark; the blur and dilation
62
66
  # manipulations may prevent registration misalignments due to stray dark pixels
63
67
  def rm_patch(c, blr=0, dlt=0)
64
- b = blr==0 ? '' : " -blur #{blr*3}x#{blr}"
65
- d = dlt==0 ? '' : " -morphology Dilate Octagon:#{dlt}"
66
- read_bytes "-crop #{c.cropper}#{b}#{d}"
68
+ params = ['-crop', c.cropper]
69
+ params.concat ['-blur', "#{blr*3}x#{blr}"] unless blr == 0
70
+ params.concat ['-morphology', 'Dilate', "Octagon:#{dlt}"] unless dlt == 0
71
+ read_bytes(*params)
67
72
  end
68
73
 
69
74
  ##################################
@@ -171,10 +176,18 @@ module Mork
171
176
 
172
177
  # calling imagemagick and capturing the converted image
173
178
  # into an array of bytes
174
- def read_bytes(params=nil)
175
- d = @density ? "-density #{@density}" : nil
176
- cmd = "magick -depth 8 #{d} #{@path} #{params} gray:-"
177
- stdout, stderr, status = Open3.capture3(cmd)
179
+ def read_bytes(*params)
180
+ # MiniMagick selects `convert` on ImageMagick 6 and `magick` on
181
+ # ImageMagick 7. Execute its argv directly to preserve binary stdout
182
+ # (MiniMagick::Tool#call strips a trailing newline) and avoid a shell.
183
+ command = MiniMagick.convert
184
+ command.depth 8
185
+ command.density @density if @density
186
+ command << @path
187
+ command.merge!(params)
188
+ command << 'gray:-'
189
+
190
+ stdout, stderr, status = Open3.capture3(*command.command)
178
191
  if status.success?
179
192
  stdout.unpack('C*')
180
193
  else
data/lib/mork/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mork
2
- VERSION = '0.18.1'
2
+ VERSION = '0.18.2'
3
3
  end
@@ -39,6 +39,30 @@ module Mork
39
39
  end
40
40
  end
41
41
 
42
+ describe 'ImageMagick command selection' do
43
+ let(:status) { instance_double(Process::Status, success?: true) }
44
+
45
+ it 'uses ImageMagick 6 convert through MiniMagick and preserves raw bytes' do
46
+ magicko = ma
47
+ allow(MiniMagick).to receive(:imagemagick7?).and_return(false)
48
+ expect(Open3).to receive(:capture3).with(
49
+ 'convert', '-depth', '8', sh.image_path, '-crop', co.cropper, 'gray:-'
50
+ ).and_return(["\x00\x0a\xff".b, '', status])
51
+
52
+ expect(magicko.rm_patch(co)).to eq [0, 10, 255]
53
+ end
54
+
55
+ it 'uses ImageMagick 7 magick through MiniMagick' do
56
+ magicko = ma
57
+ allow(MiniMagick).to receive(:imagemagick7?).and_return(true)
58
+ expect(Open3).to receive(:capture3).with(
59
+ 'magick', '-depth', '8', sh.image_path, '-crop', co.cropper, 'gray:-'
60
+ ).and_return(["\x00".b, '', status])
61
+
62
+ expect(magicko.rm_patch(co)).to eq [0]
63
+ end
64
+ end
65
+
42
66
  describe 'overlay stroke width' do
43
67
  it 'defaults to the legacy 3-pixel width' do
44
68
  expect(ma.overlay_stroke_width).to eq 3
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mork
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.1
4
+ version: 0.18.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giuseppe Bertini