Changes

Jump to navigation Jump to search
1,490 bytes added ,  09:49, 12 August 2022
m
small enhacements
== File Formats ==
ConTeXt natively supports the image formats enumerated below. The image format is determined from the file extension (case insensitive).
* '''PDF''': File extension <tt>.pdf</tt>
<td align="left"><strong>GIF</strong></td>
<td align="left"><code>.gif</code></td>
<td align="left"><code>gmconvert</code> from GraphicsMagick</td>
</tr>
<tr class="odd">
<td align="left"><strong>TIFF</strong></td>
<td align="left"><code>.tiff</code></td>
<td align="left"><code>gmconvert</code> from GraphicsMagick</td></tr><tr class="even"><td align="left"><strong>BMP</strong></td><td align="left"><code>.bmp</code></td><td align="left"><code>gm convert</code> from GraphicsMagick</td>
</tr>
</table>
The conversion generates a PDF file with prefix <tt>m_k_i_v_</tt> and a suffix <tt>.pdf</tt> added to the name of the original file. The result is cached, and the conversion is rerun re-run if the timestamp of the original file is newer than that of the converted file.
In LMTX , the file name contains md5sum of a MD5 hash of the relevant source image parameters (resolution, dimensions, ...), e.g.:
<pre>
<pre>
\startluacode
local function converterdownsampler(oldname, newname, resolution)
if not resolution or resolution == "" then
resolution = 50
end
os.execute(string.format(
'gm convert -density %ix%i "%s" "%s"',
resolution, resolution, oldname, newname)
)
-- Set the PDF and default TIFF converters to the above function.
figures.converters.tif.pdf = converterdownsamplerfigures.converters.tif.default = converterdownsampler-- Hint: This works also for jpg or png!
\stopluacode
</pre>
See also: https://source.contextgarden.net/tex/context/base/mkiv/{{src|grph-inc.lua}}
== Interaction ==
context.externalfigure({"memstream:///inline"})
\stopluacode
</texcode>
 
== Custom Processing ==
 
The following example changes the width of images based on file name extensions:
 
<texcode>
\setupexternalfigures[
location={local,global,default},
width=\textwidth
]
\defineexternalfigure[svg][width=1cm]
\defineexternalfigure[jpg][width=2cm]
\defineexternalfigure[png][width=4cm]
 
% Won't be applied because there's no process action.
% Default (\textwidth) is used, as defined above.
\defineexternalfigure[pdf][width=6cm]
 
\starttexdefinition includegraphics #1
\splitfilename{#1}
 
\processaction[\splitofftype][
jpg=>{\externalfigure[#1][jpg]},
png=>{\externalfigure[#1][png]},
svg=>{\externalfigure[#1][svg][conversion=mp]},
default=>{\externalfigure[#1]},
unknown=>{\externalfigure[#1]}
]
\stoptexdefinition
 
\starttext
\includegraphics{kitten.jpg}
\includegraphics{mill.png}
\includegraphics{cow.pdf}
\includegraphics{tiger.svg}
\stoptext
</texcode>
 
It's also possible to use {{cmd|setfigureconversion}} to instruct ConTeXt to use MetaPost when rendering SVG files. Such as:
 
<texcode>
\setfigureconversion[svg][mp]
 
\starttext
\externalfigure[kitten.jpg][width=2cm]
\externalfigure[mill.png] [width=4cm]
\externalfigure[cow.pdf] [width=6cm]
\externalfigure[tiger.svg] [width=1cm]
\stoptext
</texcode>

Navigation menu