workflows-graphics.tex /size: 7814 b    last modification: 2023-12-21 09:43
1% language=us runpath=texruns:manuals/workflows
2
3\environment workflows-style
4
5\startcomponent workflows-graphics
6
7\startchapter[title=Graphics]
8
9\startsection[title=Bad names]
10
11After many years of using \CONTEXT\ in workflows where large amounts of source
12files as well as graphics were involved we can safely say that it's hard for
13publishers to control the way these are named. This is probably due to the fact
14that in a click|-|and|-|point based desktop publishing workflow names don't
15matter as one stays on one machine, and names are only entered once (after that
16these names become abstractions and get cut and pasted). Proper consistent
17resource managament is simply not part of the flow.
18
19This means that you get names like:
20
21\starttyping
22foo_Bar_01_03-a.EPS
23foo__Bar-01a_03.eps
24foo__Bar-01a_03.eps
25foo BarA  01-03.eps
26\stoptyping
27
28Especially when a non proportional screen font is used multiple spaces can look
29like one. In fancy screen fonts upper and lowercase usage might get obscured. It
30really makes one wonder if copy|-|editing or adding labels to graphics isn't
31suffering from the same problem.
32
33Anyhow, as in an automated rendering workflow the rendering is often the last
34step you can imagine that when names get messed up it's that last step that gets
35blamed. It's not that hard to sanitize names of files on disk as well as in the
36files that refer to them, and we normally do that we have complete control. This
37is no option when all the resources are synchronzied from elsewhere. In that case
38the only way out is signaling potential issues. Say that in the source file there
39is a reference:
40
41\starttyping
42foo_Bar_01_03-a.EPS
43\stoptyping
44
45and that the graphic on disk has the same name, but for some reason after an
46update has become:
47
48\starttyping
49foo-Bar_01_03-a.EPS
50\stoptyping
51
52The old image is probably still there so the update is not reflected in the final
53product. This is not that uncommon when you deal with tens of thousands of files,
54many editors and graphic designers, and no strict filename policy.
55
56For this we provide the following tracing option:
57
58\starttyping
59\enabletrackers[graphics.lognames]
60\stoptyping
61
62This will put information in the log file about included graphics, like:
63
64\starttyping
65system          > graphics > start names
66
67used graphic    > asked   : cow.pdf
68used graphic    > comment : not found
69used graphic    > asked   : t:/sources/cow.pdf
70used graphic    > format  : pdf
71used graphic    > found   : t:/sources/cow.pdf
72used graphic    > used    : t:/sources/cow.pdf
73
74system          > graphics > stop names
75\stoptyping
76
77You can also add information to the file itself:
78
79\starttyping
80\usemodule[s-figures-names]
81\stoptyping
82
83Of course that has to be done at the end of the document. Bad names are reported
84and suitable action can be taken.
85
86\stopsection
87
88\startsection[title=Downsampling]
89
90You can plug in you rown converter, here is an example:
91
92\starttyping
93\startluacode
94
95figures.converters.jpg = figures.converters.jpg or { }
96
97figures.converters.jpg["lowresjpg.pdf"] =
98  function(oldname,newname,resolution)
99    figures.programs.run (
100      [[gm]],
101      [[convert -geometry %nx%x%ny% -compress JPEG "%old%" "%new%"]],
102      {
103         old = old,
104         new = new,
105         nx  = resolution or 300,
106         ny  = resolution or 300,
107      }
108    )
109  end
110\stopluacode
111\stoptyping
112
113You can limit the search to a few types and set the resolution with:
114
115\starttyping
116\setupexternalfigures
117  [order={pdf,jpg},
118   resolution=100,
119   method=auto]
120\stoptyping
121
122And use it like:
123
124\starttyping
125\externalfigure[verybig.jpg][height=10cm]
126\stoptyping
127
128The second string passed to the \type {run} helper contains the arguments to the
129first one. The variables between percent signs get replaced by the variables in
130the tables passed as third argument.
131
132\stopsection
133
134\startsection[title=Trackers]
135
136If you want a lot of info you can say:
137
138\starttyping
139\enabletrackers[figures.*]
140\stoptyping
141
142But you can be more specific. With \type {graphics.locating} you will get some
143insight in where files are looked for. The \type {graphics.inclusion} tracker
144gives some more info about actual inclusion. The \type {graphics.bases} is kind
145of special and only makes sense when you use the graphic database options. The
146\type {graphics.conversion} and related tracker \type {graphics.programs} show if
147and how conversion of images takes place.
148
149The \type {graphics.lognames} will make sure that some extra information about
150used graphics is saved in the log file, The \type {graphics.usage} tracker will
151produce a file \typ {<jobname>-figures-usage.lua} that contains information about
152found (or not found) images and the way they are used.
153
154\stopsection
155
156\startsection[title=Compression]
157
158A \PNG\ image uses several methods for compression. The image data itself can be
159compacted by taking pixels around each individual pixel into account. Storing
160deltas instead of absolute values can for instance result in strips of zeros.
161These in turn compress well using zlib compression. Each scanline starts with a
162filterbyte that indicates how to look at the surrounding pixels. While in \PDF\ a
163\JPEG\ image is included as|-|is, a \PNG\ often take a bit more work. A
164(optional) mask has to be split off, as does an (optional) index. In the worst
165case we need to deinterlace. The \PNG\ inclusion mechanism in \CONTEXT\ \LMTX\
166takes care of this in an as efficient as possible way. Nevertheless there are
167some knobs you can turn:
168
169\starttyping
170\enabledirectives[graphics.png.recompress]
171\enabledirectives[graphics.png.compresslevel=9]
172\stoptyping
173
174A higher compress level makes the run somewhat smaller but also fives smaller
175files. The default compress level is~3. When an image doesn't need to be
176transformed (due to mask, index or interlace), you have to force recompression
177with the \type {recompress} directive. The sample image \type {mill.png} has a
178size of \type {154,869} bytes.
179
180\starttyping
181\startTEXpage
182    \externalfigure[mill.png]
183\stopTEXpage
184\stoptyping
185
186The next table shows the consequences of setting the directives. The runtime is
187of course dependent of the machine you run the sample on. If you have lots of
188images it might make sense to have a final run with a higher compress level. The
189\PDF\ file has some extra overhead (like metadata and page related information).
190
191\starttabulate[|l|c|c|c|]
192\BC               \BC compression \BC filesize \BC runtime \NC \NR
193\BC default       \NC             \NC 156,964  \NC 0.516   \NC \NR
194\BC recompress    \NC 3           \NC 144,418  \NC 0.531   \NC \NR
195\BC compresslevel \NC 0           \NC 281,071  \NC 0.516   \NC \NR
196\BC compresslevel \NC 9           \NC 137,375  \NC 0.547   \NC \NR
197\stoptabulate
198
199\stopsection
200
201\startsection[title=Remote]
202
203You can include images from a remote location using a \URL\ specification.
204
205\starttyping
206\externalfigure[https://www.pragma-ade.com/logo-ade.png] % via curl
207\externalfigure[http://www.pragma-ade.com/logo-ade.png]  % via socket
208\stoptyping
209
210Normally the socket library will be used for \type {http} and Curl for \type
211{https}. Images are cached and there is some threshold that makes sure that we
212don't keep fetching. You can set the threshold to zero seconds to avoid that:
213
214\starttyping
215\enabledirectives[schemes.threshold=0]
216\stoptyping
217
218In \LMTX\ there are some more options:
219
220\starttyping
221\enabledirectives[schemes.inmemory]
222\enabledirectives[schemes.uselibrary]
223\stoptyping
224
225The first option avoid storing an image in a file and therefore consumes a bit
226more memory and the second one tries to use the Curl library instead of calling
227the program. If you want ot see what is going on you can use:
228
229\starttyping
230\enabletrackers[resolvers.schemes]
231\enabletrackers[graphics.locating]
232\enabletrackers[resolvers.virtual]
233\stoptyping
234
235\stopsection
236
237\stopchapter
238
239\stopcomponent
240
241