1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
%D \module
%D [ file=meta-imp-magick,
%D version=2021.08.03,
%D title=\METAPOST\ Graphics,
%D subtitle=Magick Manipulations,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
\registerctxluafile{libs-imp-graphicsmagick}{autosuffix}
\startluacode
function mp.lmt_magick_convert()
local specification = metapost.getparameterset("magick")
local inputname = specification.filename
if inputname then
-- we don't want to trigger reuse when we have the same input file
local hash = md5.HEX(table.sequenced(specification))
local outputname = file.addsuffix("m_k_i_v_mp_fuzzy_" .. hash,file.suffix(inputname))
luatex.registertempfile(outputname)
-- make the table a bit unique and don't polute it
local whattodo = table.setmetatableindex( {
inputname = inputname,
outputname = outputname,
}, specification)
-- now do the magick
utilities.graphicsmagick.convert(whattodo)
-- and return the result
return [[figure("]] .. outputname .. [[")]]
else
-- bad luck
return [[textext("missing filename")]]
end
end
\stopluacode
\startMPdefinitions
presetparameters "magick" [
filename = "unset",
% blur = [ radius = 10, sigma = 5 ],
% noise = [ type = 4 ],
] ;
def lmt_magick = applyparameters "magick" "lmt_do_magick" enddef ;
vardef lmt_do_magick = lua.mp.lmt_magick_convert() enddef ;
\stopMPdefinitions
\continueifinputfile{meta-imp-magick.mkxl}
\enabletrackers[*lib*]
\startMPpage
draw lmt_magick [
filename = "hacker.jpg",
blur = [ radius = 10, sigma = 5 ],
noise = [ type = 2 ],
] ysized 4cm ;
draw lmt_magick [
filename = "hacker.jpg",
blur = [ radius = 5, sigma = 3 ],
noise = [ type = 4 ],
] ysized 4cm shifted (0, -4cm) ;
draw lmt_magick [
filename = "hacker.jpg",
blur = [ radius = 10, sigma = 5 ],
noise = [ type = 4 ],
] ysized 4cm shifted (0, -8cm) ;
\stopMPpage
|