1if 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
9if true then
10 logs.report("warning","swiglib is no longer supported")
11end
12
13local graphicmagick = utilities.graphicmagick or { }
14utilities.graphicmagick = graphicmagick
15
16local report_gm = logs.reporter("swiglib graphicsmagick")
17
18local gm = swiglib("graphicsmagick.core")
19
20if gm then
21 report_gm("library loaded")
22
23else
24 return
25end
26
27local nofruns = 0
28
29function graphicmagick.convert(specification)
30
31 nofruns = nofruns + 1
32 statistics.starttiming(graphicmagick)
33
34 local inputname = specification.inputname
35 if not inputname or inputname == "" then
36 report_gm("invalid run %s, no inputname specified",nofruns)
37 statistics.stoptiming(graphicmagick)
38 return false
39 end
40 local outputname = specification.outputname
41 if not outputname or outputname == "" then
42 outputname = file.replacesuffix(inputname,"pdf")
43 end
44
45 if not lfs.isfile(inputname) then
46 report_gm("invalid run %s, input file %a is not found",nofruns,inputname)
47 statistics.stoptiming(graphicmagick)
48 return false
49 end
50
51 report_gm("run %s, input file %a, outputfile %a",nofruns,inputname,outputname)
52 local magick_wand = gm.NewMagickWand()
53 gm.MagickReadImage(magick_wand,inputname)
54 gm.MagickWriteImage(magick_wand,outputname)
55 gm.DestroyMagickWand(magick_wand)
56
57 statistics.stoptiming(graphicmagick)
58end
59
60function graphicmagick.statistics(report)
61 local runtime = statistics.elapsedtime(graphicmagick)
62 if report then
63 report_gm("nofruns %s, runtime %s",nofruns,runtime)
64 else
65 return {
66 runtime = runtime,
67 nofruns = nofruns,
68 }
69 end
70end
71
72
73
74 |