Changes

Jump to navigation Jump to search
m
Fixed one typo, one small grammatical error.
< [[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 ==
<texcode>\setupexternalfigures[location={local,global}]</texcode>
The ConTeXt distribution includes three sample images: <tt>cow.pdf</tt>, <tt>mill.png</tt>, and <tt>hacker.jpg</tt>, that are useful when creating minimum working examples to illustrate a bug on the mailing list. These images are locating located in the <tt>TEXMF</tt> directory. To add the <tt>TEXMF</tt> directory to the image search path, use:
<texcode>\setupexternalfigures[location={local,global,default}]</texcode>
When a document containing a remote file is compiled for the first time, the remote file is downloaded from the server and stored in the LuaTeX cache directory. This cached file is used during subsequent runs.
Normally, the remote image is downloaded again if the image in the cache is older than 1~day. To change this threshold to, for example, 2<sub>minutes (120</sub>seconds), either add
<texcode>\enabledirectives[schemes.threshold=120]</texcode>
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:
<texcode>\clip[nx=3,ny=3,x=2,y=2]
{\externalfigure[logo.pdf]}</texcode>
 
 
In PDF files, it is possible to specify different size information in PDF headers MediaBox, TrimBox, CropBox, and ArtBox. To clip to one of these sizes, use
 
<texcode>\externalfigure[logo.pdf][size=art]</texcode>
 
Other options are: `none` (detault), `media` for MediaBox, `crop` for CropBox, `trim` for TrimBox, and `art` for ArtBox.
= Troubleshooting =
ConTeXt includes a Perl script <tt>pdftrimwhite</tt> that removes extra white space at the borders of a PDF file. To run this script:
<pre>mtxrun --script pdftrimwhite <em>[flags] input output</em></pre>
The most important flag is <tt>--offset=dimen</tt>, which keeps some extra space around the trimmed image.
= [[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 Linux release of acroread doesn't support that. An alternative solution consists in launching your prefered player (MPlayer) from acroread:
<texcode>
</nowiki></pre>
= See Also =
 
* [[Animation]]
* [[Example photo page layout]]
* [[Graphical_text_manipulation|scaling, rotating, mirroring, clipping]]
[[Category:Graphics]]
 
 
{{Getting started navbox}}
38

edits

Navigation menu