grph-wnd.lua /size: 1710 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
grph-wnd
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to grph-inc.mkiv
"
,
4
author
=
"
Hans Hagen, PRAGMA-ADE, Hasselt NL
"
,
5
copyright
=
"
PRAGMA ADE / ConTeXt Development Team
"
,
6
license
=
"
see context related readme files
"
7
}
8 9
-- Thanks to Luigi Scarso for making graphic magic work in luatex.
10
--
11
-- \externalfigure[hacker.jpeg][width=4cm,conversion=gray.jpg]
12 13
local
converters
,
suffixes
=
figures
.
converters
,
figures
.
suffixes
14 15
local
trace_conversion
=
false
trackers
.
register
(
"
figures.conversion
"
,
function
(
v
)
trace_conversion
=
v
end
)
16 17
local
report_wand
=
logs
.
reporter
(
"
graphics
"
,
"
wand
"
)
18 19
local
function
togray
(
oldname
,
newname
)
20
if
lfs
.
isfile
(
oldname
)
then
21
require
(
"
gmwand
"
)
22
if
trace_conversion
then
23
report_wand
(
"
converting %a to %a using gmwand
"
,
oldname
,
newname
)
24
end
25
gmwand
.
InitializeMagick
(
"
./
"
)
-- What does this path do?
26
local
wand
=
gmwand
.
NewMagickWand
(
)
27
gmwand
.
MagickReadImage
(
wand
,
oldname
)
28
gmwand
.
MagickSetImageColorspace
(
wand
,
gmwand
.
GRAYColorspace
)
29
gmwand
.
MagickWriteImages
(
wand
,
newname
,
1
)
30
gmwand
.
DestroyMagickWand
(
wand
)
31
else
32
report_wand
(
"
unable to convert %a to %a using gmwand
"
,
oldname
,
newname
)
33
end
34
end
35 36
local
formats
=
{
"
png
"
,
"
jpg
"
,
"
gif
"
}
37 38
for
i
=
1
,
#
formats
do
39
local
oldformat
=
formats
[
i
]
40
local
newformat
=
"
gray.
"
.
.
oldformat
41
if
trace_conversion
then
42
report_wand
(
"
installing converter for %a to %a
"
,
oldformat
,
newformat
)
43
end
44
converters
[
oldformat
]
=
converters
[
oldformat
]
or
{
}
45
converters
[
oldformat
]
[
newformat
]
=
togray
46
suffixes
[
newformat
]
=
oldformat
47
end
48