util-lib-imp-gm.lua /size: 2084 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
util-lib-imp-gm
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
a mkiv swiglib module
"
,
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
local
graphicmagick
=
utilities
.
graphicmagick
or
{
}
10
utilities
.
graphicmagick
=
graphicmagick
11 12
local
report_gm
=
logs
.
reporter
(
"
swiglib graphicsmagick
"
)
13 14
local
gm
=
swiglib
(
"
graphicsmagick.core
"
)
15 16
if
gm
then
17
report_gm
(
"
library loaded
"
)
18
-- inspect(table.sortedkeys(gm))
19
else
20
return
21
end
22 23
local
nofruns
=
0
24 25
function
graphicmagick
.
convert
(
specification
)
26
--
27
nofruns
=
nofruns
+
1
28
statistics
.
starttiming
(
graphicmagick
)
29
--
30
local
inputname
=
specification
.
inputname
31
if
not
inputname
or
inputname
=
=
"
"
then
32
report_gm
(
"
invalid run %s, no inputname specified
"
,
nofruns
)
33
statistics
.
stoptiming
(
graphicmagick
)
34
return
false
35
end
36
local
outputname
=
specification
.
outputname
37
if
not
outputname
or
outputname
=
=
"
"
then
38
outputname
=
file
.
replacesuffix
(
inputname
,
"
pdf
"
)
39
end
40
--
41
if
not
lfs
.
isfile
(
inputname
)
then
42
report_gm
(
"
invalid run %s, input file %a is not found
"
,
nofruns
,
inputname
)
43
statistics
.
stoptiming
(
graphicmagick
)
44
return
false
45
end
46
--
47
report_gm
(
"
run %s, input file %a, outputfile %a
"
,
nofruns
,
inputname
,
outputname
)
48
local
magick_wand
=
gm
.
NewMagickWand
(
)
49
gm
.
MagickReadImage
(
magick_wand
,
inputname
)
50
gm
.
MagickWriteImage
(
magick_wand
,
outputname
)
51
gm
.
DestroyMagickWand
(
magick_wand
)
52
--
53
statistics
.
stoptiming
(
graphicmagick
)
54
end
55 56
function
graphicmagick
.
statistics
(
report
)
57
local
runtime
=
statistics
.
elapsedtime
(
graphicmagick
)
58
if
report
then
59
report_gm
(
"
nofruns %s, runtime %s
"
,
nofruns
,
runtime
)
60
else
61
return
{
62
runtime
=
runtime
,
63
nofruns
=
nofruns
,
64
}
65
end
66
end
67 68
-- graphicmagick.convert { inputname = "t:/sources/hacker.jpg", outputname = "e:/tmp/hacker.png" }
69
-- graphicmagick.statistics(true)
70