1if 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
10
11
12
13local converters , suffixes = figures . converters , figures . suffixes
14
15local trace_conversion = false trackers . register ( " figures.conversion " , function ( v ) trace_conversion = v end )
16
17local report_wand = logs . reporter ( " graphics " , " wand " )
18
19local 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 ( " ./ " )
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
34end
35
36local formats = { " png " , " jpg " , " gif " }
37
38for 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
47end
48 |