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 +4 -4
- data/lib/mork/magicko.rb +22 -9
- data/lib/mork/version.rb +1 -1
- data/spec/mork/magicko_spec.rb +24 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8cdb6af94ff682ccad23d669fb624d263ea4fb28d5911e3ada2ceeb200c8fd4a
|
|
4
|
+
data.tar.gz: 956342c055f892ee7e4c44187711b3660eefd8fcee68723bfd1cb2fb245d0a75
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
data/spec/mork/magicko_spec.rb
CHANGED
|
@@ -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
|