Changes

Jump to navigation Jump to search
896 bytes added ,  09:49, 12 August 2022
m
small enhacements
< [[Graphics]] | [[Combinations]] | [[File Formats|Supported Media File Formats]] | [[Including pages from PDF documents]] | [[Animation]] | [[Downsampling]] >
 
= Usage =
== 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>
* '''JPEG 2000''': File extension <tt>.jp2</tt>
* '''JBIG''' or '''JBIG2''': File extension <tt>.jbig</tt>, <tt>.jbig2</tt>, or <tt>.jb2</tt>
 
An old page (2010), gives details on supported [[File Formats|file formats]]
== Image Conversion ==
<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 a MD5 hash of the relevant source image parameters (resolution, dimensions, ...), e.g.: <pre>hacker_jpg_c60ccda70ef92e32d7a6334f31c23259.gray.pdf </pre>
It is possible to change the converter used with the following code:
<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 ==
By default, the interactive elements of the included PDF file are discarded. To enable the interactive elements of the included PDF file, use
<texcode>\externalfigure[filename.pdf][interaction=yes]</texcode>
 
For further reading, don't forget [[Including pages from PDF documents]].
== Image Directory ==
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>
== Image Scaling ==
 
{{ note | If either <tt>width</tt> or <tt>height</tt> is specified, then the <tt>scale</tt> key has no effect. }}
 
To scale an image use the <tt>scale</tt> key: <tt>scale=1000</tt> corresponds to the original dimensions of the image, <tt>scale=500</tt> scales the image to 50% of the original size, <tt>scale=1500</tt> scales the images to 150% of the original size, and so on. For example:
<texcode>\externalfigure[logo.pdf][scale=500]</texcode>
 
scales the image to 50% of its size.
Use <tt>\setupexternalfigures</tt> to set the scale of all images. For example, to scale all images to be twice their original size, use:
<texcode>\setupexternalfigures[scale=2000]</texcode>
 
If either <tt>width</tt> or <tt>height</tt> is specified, then the <tt>scale</tt> key has no effect.
In addition, the <tt>xscale</tt> and <tt>yscale</tt> keys scale the image in only one dimension. For example:
= [[Floating Objects]] =
 
Floats are numbered and placed by ConTeXt, with a configurable (and optional) caption.
 
<texcode>
\placefigure[place]{My Caption}{\externalfigure[myone]}
</texcode>
<tt>place</tt> is one of:
left, right, here, top, bottom, inleft, inright, inmargin, margin, page, opposite, always, force, tall
 
You get ''no'' caption with <tt>none</tt>.
You get a table of figures with {{cmd|showexternalfigures}}<code>[alternative=a]</code>. Alternatives (styles) a, b and c are predefined.
 
The second brackets of {{cmd|placefigure}} can contain any command, e.g. {{cmd|getbuffer}}.
 
You find more about floats ([[Floating Objects]]) in the manual.
= Movies =
<tt>preview=yes</tt> shows the first image as preview.
You find more about interactive Elements in [http://www.pragma-ade.comnl/general/manuals/mwidget-s.pdf mwidget-s.pdf]
Unfortunately, people who are fond of Linux cannot embed movies because the linux release of acroread doesn't support that. An alternative solution consists in launching your prefered player (MPlayer) from acroread:
</nowiki></pre>
= See Also =
 
* [[Animation]]
* [[Example photo page layout]]
* [[Graphical_text_manipulation|scaling, rotating, mirroring, clipping]]
[[Category:Graphics]]
 
 
{{Getting started navbox}}

Navigation menu