Changes

Jump to navigation Jump to search
2 bytes removed ,  19:52, 30 March 2014
m
no edit summary
<texcode>\externalfigure[logo.pdf]</texcode>
This command places the PDF image <tt>logo.pdf</tt> in a <tt>\{{cmd|vbox</tt>}}; the width and height of the image are equal to the natural dimensions of the image.
To set the width of the image to a specific size, say <tt>1cm</tt>, use:
</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 if the timestamp of the original file is newer than that of the converted file.
<texcode>\setupexternalfigures
[directory={images, /home/user/images}]</texcode>
 Note that one should : always use forward slashes in path names, ''even on Windows''regardless of operating system.
The default search order is: the current directory, the parent directory, the grand-parent directory, and then the paths specified by the <tt>directory</tt> key. To restrict image search only to the paths specified by the <tt>directory</tt> key, use:
<texcode>\setupexternalfigures
[location=global]</texcode>
 
To restore the default search behavior, use:
<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 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>
 
The above alternative adds the ''entire'' <tt>TEXMF</tt> directory to the search path, ''including the'' <tt>doc/</tt> ''directory!'' Therefore, one needs to be extremely careful when using this option. In fact, I would advise not using <tt>location=default</tt> except for illustrative minimal working examples.
<texcode>\enabledirectives[schemes.threshold=120]</texcode>
 
in the ConTeXt file, or compile the ConTeXt file using the command
</texcode>
Replace "`http://proxy.example.com:3128" ` with the proxy URL.
To disable the proxy again:
\ctxlua{http = require("socket.http"); http.PROXY = nil}
</texcode>
 
= Image transformations =
<texcode>\externalfigure[logo.pdf][scale=500]</texcode>
 
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.
<texcode>\externalfigure[logo.pdf][xscale=500]
\externalfigure[logo.pdf][yscale=500]</texcode>
== Specifying maximum size of an image ==
Oftentimes, we don't want the == Restrict Image Dimensions == ConTeXt can limit included image images to be greater than a particular sizedimensions. For example, to ensure that an included image is not more than <tt>0.2\textwidth</tt>:
<texcode>\externalfigure[logo.pdf][maxwidth=0.2\textwidth]</texcode>
 
If <tt>maxwidth</tt> is specified and the width of the image is less than <tt>maxwidth</tt>, then the image is not scaled; if the width of the image is greater than <tt>maxwidth</tt>, then the width is restricted to <tt>maxwidth</tt> and the height is scaled appropriately to maintain the original aspect ratio.
[maxwidth=\textwidth,
maxheight=0.8\textheight]</texcode>
== Rotating images ==
To rotate the == Rotate images == Rotate included image images by 9090°, 180180°, or 270 degrees, use 270° using the <tt>orientation</tt> key. For example:
<texcode>\externalfigure[logo.pdf][orientation=90]</texcode>
 To rotate by an arbitrary angle, use the <tt>\{{cmd|rotate</tt> }} command. For example:
<texcode>\rotate[rotation=45]{\externalfigure[logo.pdf]}</texcode>
== Mirroring images ==
== Mirror Images == To mirror (flip) an image, use the generic <tt>\{{cmd|mirror</tt> }} command. For example, to mirror horizontally:
<texcode>\mirror{\externalfigure[logo.pdf]}</texcode>
 
To mirror vertically, first rotate the image by 180° and then mirror it:
<texcode>\mirror{\externalfigure[logo.pdf][orientation=180]}</texcode>
 
== Clipping images ==
To clip Clip an image, use using the generic <tt>\{{cmd|clip</tt> }} command. For example, to clip the original image to a <tt>1cm x 2cm</tt> rectangle at an offset of <tt>(3mm,5mm)</tt> from the top left corner:
<texcode>\clip[width=1cm, height=2cm, hoffset=3mm, voffset=5mm]
{\externalfigure[logo.pdf]}</texcode>
 
As another example, this cuts the image into a <tt>3x3</tt> pieces and then outputs the <tt>(2,2)</tt> piece:
<texcode>\clip[nx=3,ny=3,x=2,y=2]
{\externalfigure[logo.pdf]}</texcode>
 
= Troubleshooting =
This section describes various tips for discovering problems with embedded images. == Visualizing the image bounding box Visualize Bounding Box ==
If, for instance, the image is taking more space than expected, it can be useful to visualize the bounding box of the image. To do this:
<texcode>\externalfigure[logo.pdf][frame=on]</texcode>
 
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.
Similar functionality is provided by another Perl script, <tt>pdfcrop</tt>, that is included in most TeX distributions.
== Diagnostic Tracking what is happening ==
To get diagnostic information about image inclusion, enable the tracker <tt>graphics.locating</tt> either by editing the ConTeXt file and adding:
<texcode>\enabletrackers[graphics.locating]</texcode>
in the ConTeXt fileAlternatively, or by compiling compile the ConTeXt file using the command:
<texcode>context --trackers=graphics.locating filename</texcode>
 
The tracker writes diagnostics to the console. Suppose we use <tt>\externalfigure[somefile.pdf]</tt> and ConTeXt finds the file in the current search path; then the following information is printed on the console:
<texcode>\useMPlibrary[dum]</texcode>
 
Then, whenever an image file is not found in the current search path, a random MetaPost image is shown in the output.
<context> </context>
== Images at the beginning of a paragraph Leading Paragraph ==
Using {{cmd|externalfigure}}<tt>\externalfigure[...]</tt> at the beginning of a paragraph results in a line break after the image. This is because <tt>\{{cmd|externalfigure</tt> }} is a <tt>\{{cmd|vbox</tt> }} and when  encounters a <tt>\{{cmd|vbox</tt> }} is encountered at (what appears to be) the beginning of a paragraph, it remains in vertical mode. To prevent this, add <tt>\{{cmd|dontleavehmode</tt> }} before <tt>\{{cmd|externalfigure</tt>}}, like this:
<texcode>\dontleavehmode
\externalfigure[...] ... first line ...</texcode>
= Settings for multiple images =
= Multiple Image Settings = == Image settings Settings ==
Suppose your document contains many side-by-side images, and you want all of these images to be of the same size. In addition, you want to control the size of all images by changing only one setup. To do this, you can use the <tt>\{{cmd|defineexternalfigure</tt> }} macro, which defines a named collection of image settings. For example, to define a collection where the image width is <tt>3cm</tt>, use:
<texcode>\defineexternalfigure[logo-settings]
[width=3cm]</texcode>
 
And then to use these settings in an image, use:
<texcode>\externalfigure[group.pdf][logo-settings]</texcode>
 
or, if you want to add or override settings, use:
<texcode>\externalfigure[group.pdf][logo-settings]
[height=2cm]</texcode>
== Labeled images ==
== Image Labels == Suppose your document contains an image at multiple locations; all of these images are to be of the same size, which is not necessarily the same as the natural size of the image. Furthermore, as before, you want to set the size of all the images by changing only one setup. Here, the macro to use is <tt>\{{cmd|useexternalfigure</tt>}}, which defines a symbolic label for inserting an image plus settings. For example:
<texcode>\useexternalfigure[mylogo]
[logo.pdf][width=2cm]</texcode>
 
defines an image label <tt>mylogo</tt> that maps to the image file <tt>logo.pdf</tt> and sets its width to <tt>2cm</tt>. This image label may be used as a normal image filename:
<texcode>\externalfigure[mylogo]</texcode>
 
 
 
= Place picture in the text =
If you want to have the image to the right, you can do:
 
<texcode>
\setuppapersize[A5]
There are more options (distance can even be negative):
 
<texcode>
\setuppapersize[A5]
Movies aren't recognized automatically yet, you need a more verbose declaration:
 
<texcode>
\externalfigure[demo.mov][label=demo,width=4cm,height=4cm,preview=yes]
</texcode>
 
<tt>preview=yes</tt> shows the first image as preview.
You find more about interactive Elements in [http://www.pragma-ade.com/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:
 
<texcode>
\defineprogram[dummy.mpeg][dummy.mpeg.sh]
== Full page images ==
 
* See [[Simple Cover Page]]
</texcode>
== See also ==
== See also ==
* [[Animation]]
* [[Example photo page layout]]
419

edits

Navigation menu