{"route":"/en-US-v0.14.1/reference/visualize/image/","title":"Image","description":"Documentation for the `image` function.","part":null,"outline":[{"id":"summary","name":"Summary","children":[]},{"id":"example","name":"Example","children":[]},{"id":"parameters","name":"Parameters","children":[{"id":"parameters-source","name":"source","children":[]},{"id":"parameters-format","name":"format","children":[]},{"id":"parameters-width","name":"width","children":[]},{"id":"parameters-height","name":"height","children":[]},{"id":"parameters-alt","name":"alt","children":[]},{"id":"parameters-page","name":"page","children":[]},{"id":"parameters-fit","name":"fit","children":[]},{"id":"parameters-scaling","name":"scaling","children":[]},{"id":"parameters-icc","name":"icc","children":[]}]},{"id":"definitions","name":"Definitions","children":[{"id":"definitions-decode","name":"Decode Image","children":[{"id":"definitions-decode-data","name":"data","children":[]},{"id":"definitions-decode-format","name":"format","children":[]},{"id":"definitions-decode-width","name":"width","children":[]},{"id":"definitions-decode-height","name":"height","children":[]},{"id":"definitions-decode-alt","name":"alt","children":[]},{"id":"definitions-decode-fit","name":"fit","children":[]},{"id":"definitions-decode-scaling","name":"scaling","children":[]}]}]}],"body":{"kind":"func","content":{"path":[],"name":"image","title":"Image","keywords":[],"oneliner":"A raster or vector graphic.","element":true,"contextual":false,"deprecationMessage":null,"deprecationUntil":null,"details":[{"kind":"html","content":"<p>A raster or vector graphic.</p>\n<p>You can wrap the image in a <a href=\"/en-US-v0.14.1/reference/model/figure/\" title=\"`figure`\"><code>figure</code></a> to give it a number and caption.</p>\n<p>Like most elements, images are <em>block-level</em> by default and thus do not\nintegrate themselves into adjacent paragraphs. To force an image to become\ninline, put it into a <a href=\"/en-US-v0.14.1/reference/layout/box/\" title=\"`box`\"><code>box</code></a>.</p>\n<h2 id=\"example\">Example</h2>\n<div class=\"previewed-code\"><pre><code><span class=\"typ-func\">#</span><span class=\"typ-func\">figure</span><span class=\"typ-punct\">(</span>\n  <span class=\"typ-func\">image</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;molecular.jpg&quot;</span><span class=\"typ-punct\">,</span> width<span class=\"typ-punct\">:</span> <span class=\"typ-num\">80%</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span>\n  caption<span class=\"typ-punct\">:</span> <span class=\"typ-punct\">[</span>\n    A step in the molecular testing\n    pipeline of our lab.\n  <span class=\"typ-punct\">]</span><span class=\"typ-punct\">,</span>\n<span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/ce75a73e1e074f91aba6411c6e77cec4.png\" alt=\"Preview\"></div></div>"}],"self":false,"params":[{"name":"source","details":[{"kind":"html","content":"<p>A <a href=\"/en-US-v0.14.1/reference/syntax/#paths\">path</a> to an image file or raw bytes making up an\nimage in one of the supported <a href=\"/en-US-v0.14.1/reference/visualize/image/#parameters-format\">formats</a>.</p>\n<p>Bytes can be used to specify raw pixel data in a row-major,\nleft-to-right, top-to-bottom format.</p>"},{"kind":"example","content":{"body":"<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> original <span class=\"typ-op\">=</span> <span class=\"typ-func\">read</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;diagram.svg&quot;</span><span class=\"typ-punct\">)</span>\n<span class=\"typ-key\">#</span><span class=\"typ-key\">let</span> changed <span class=\"typ-op\">=</span> original<span class=\"typ-punct\">.</span><span class=\"typ-func\">replace</span><span class=\"typ-punct\">(</span>\n  <span class=\"typ-str\">&quot;#2B80FF&quot;</span><span class=\"typ-punct\">,</span> <span class=\"typ-comment\">// blue</span>\n  green<span class=\"typ-punct\">.</span><span class=\"typ-func\">to-hex</span><span class=\"typ-punct\">(</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span>\n<span class=\"typ-punct\">)</span>\n\n<span class=\"typ-func\">#</span><span class=\"typ-func\">image</span><span class=\"typ-punct\">(</span><span class=\"typ-func\">bytes</span><span class=\"typ-punct\">(</span>original<span class=\"typ-punct\">)</span><span class=\"typ-punct\">)</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">image</span><span class=\"typ-punct\">(</span><span class=\"typ-func\">bytes</span><span class=\"typ-punct\">(</span>changed<span class=\"typ-punct\">)</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/8c4900221f249ebaf7a8713761a0df51.png\" alt=\"Preview\"></div></div>","title":null}}],"types":["str","bytes"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"format","details":[{"kind":"html","content":"<p>The image's format.</p>\n<p>By default, the format is detected automatically. Typically, you thus\nonly need to specify this when providing raw bytes as the\n<a href=\"/en-US-v0.14.1/reference/visualize/image/#parameters-source\"><code>source</code></a> (even then, Typst will try to figure out the\nformat automatically, but that's not always possible).</p>\n<p>Supported formats are <code><span class=\"typ-str\">&quot;png&quot;</span></code>, <code><span class=\"typ-str\">&quot;jpg&quot;</span></code>, <code><span class=\"typ-str\">&quot;gif&quot;</span></code>, <code><span class=\"typ-str\">&quot;svg&quot;</span></code>,\n<code><span class=\"typ-str\">&quot;pdf&quot;</span></code>, <code><span class=\"typ-str\">&quot;webp&quot;</span></code> as well as raw pixel data.</p>\n<p>Note that several restrictions apply when using PDF files as images:</p>\n<ul>\n<li>When exporting to PDF, any PDF image file used must have a version\nequal to or lower than the <a href=\"/en-US-v0.14.1/reference/pdf/#pdf-versions\">export target PDF\nversion</a>.</li>\n<li>PDF files as images are currently not supported when exporting with a\nspecific PDF standard, like PDF/A-3 or PDF/UA-1. In these cases, you\ncan instead use SVGs to embed vector images.</li>\n<li>The image file must not be password-protected.</li>\n<li>Tags in your PDF image will not be preserved. Instead, you must\nprovide an <a href=\"/en-US-v0.14.1/reference/visualize/image/#parameters-alt\">alternative description</a> to make the image\naccessible.</li>\n</ul>\n<p>When providing raw pixel data as the <code>source</code>, you must specify a\ndictionary with the following keys as the <code>format</code>:</p>\n<ul>\n<li><code>encoding</code> (<a href=\"/en-US-v0.14.1/reference/foundations/str/\" title=\"str\">str</a>): The encoding of the pixel data. One of:\n<ul>\n<li><code><span class=\"typ-str\">&quot;rgb8&quot;</span></code> (three 8-bit channels: red, green, blue)</li>\n<li><code><span class=\"typ-str\">&quot;rgba8&quot;</span></code> (four 8-bit channels: red, green, blue, alpha)</li>\n<li><code><span class=\"typ-str\">&quot;luma8&quot;</span></code> (one 8-bit channel)</li>\n<li><code><span class=\"typ-str\">&quot;lumaa8&quot;</span></code> (two 8-bit channels: luma and alpha)</li>\n</ul>\n</li>\n<li><code>width</code> (<a href=\"/en-US-v0.14.1/reference/foundations/int/\" title=\"int\">int</a>): The pixel width of the image.</li>\n<li><code>height</code> (<a href=\"/en-US-v0.14.1/reference/foundations/int/\" title=\"int\">int</a>): The pixel height of the image.</li>\n</ul>\n<p>The pixel width multiplied by the height multiplied by the channel count\nfor the specified encoding must then match the <code>source</code> data.</p>"},{"kind":"example","content":{"body":"<div class=\"previewed-code\"><pre><code><span class=\"typ-func\">#</span><span class=\"typ-func\">image</span><span class=\"typ-punct\">(</span>\n  <span class=\"typ-func\">read</span><span class=\"typ-punct\">(</span>\n    <span class=\"typ-str\">&quot;tetrahedron.svg&quot;</span><span class=\"typ-punct\">,</span>\n    encoding<span class=\"typ-punct\">:</span> <span class=\"typ-key\">none</span><span class=\"typ-punct\">,</span>\n  <span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span>\n  format<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;svg&quot;</span><span class=\"typ-punct\">,</span>\n  width<span class=\"typ-punct\">:</span> <span class=\"typ-num\">2cm</span><span class=\"typ-punct\">,</span>\n<span class=\"typ-punct\">)</span>\n\n<span class=\"typ-func\">#</span><span class=\"typ-func\">image</span><span class=\"typ-punct\">(</span>\n  <span class=\"typ-func\">bytes</span><span class=\"typ-punct\">(</span><span class=\"typ-func\">range</span><span class=\"typ-punct\">(</span><span class=\"typ-num\">16</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">.</span><span class=\"typ-func\">map</span><span class=\"typ-punct\">(</span>x <span class=\"typ-op\">=&gt;</span> x <span class=\"typ-op\">*</span> <span class=\"typ-num\">16</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span>\n  format<span class=\"typ-punct\">:</span> <span class=\"typ-punct\">(</span>\n    encoding<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;luma8&quot;</span><span class=\"typ-punct\">,</span>\n    width<span class=\"typ-punct\">:</span> <span class=\"typ-num\">4</span><span class=\"typ-punct\">,</span>\n    height<span class=\"typ-punct\">:</span> <span class=\"typ-num\">4</span><span class=\"typ-punct\">,</span>\n  <span class=\"typ-punct\">)</span><span class=\"typ-punct\">,</span>\n  width<span class=\"typ-punct\">:</span> <span class=\"typ-num\">2cm</span><span class=\"typ-punct\">,</span>\n<span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/10ff96fc3a10fde3da637ec12b56637a.png\" alt=\"Preview\"></div></div>","title":null}}],"types":["auto","str","dictionary"],"strings":[{"string":"png","details":"<p>Raster format for illustrations and transparent graphics.</p>"},{"string":"jpg","details":"<p>Lossy raster format suitable for photos.</p>"},{"string":"gif","details":"<p>Raster format that is typically used for short animated clips. Typst can\nload GIFs, but they will become static.</p>"},{"string":"webp","details":"<p>Raster format that supports both lossy and lossless compression.</p>"},{"string":"svg","details":"<p>The vector graphics format of the web.</p>"},{"string":"pdf","details":"<p>High-fidelity document and graphics format, with focus on exact\nreproduction in print.</p>"}],"default":"<code><span class=\"typ-key\">auto</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"width","details":[{"kind":"html","content":"<p>The width of the image.</p>"}],"types":["auto","relative"],"strings":[],"default":"<code><span class=\"typ-key\">auto</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"height","details":[{"kind":"html","content":"<p>The height of the image.</p>"}],"types":["auto","relative","fraction"],"strings":[],"default":"<code><span class=\"typ-key\">auto</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"alt","details":[{"kind":"html","content":"<p>An alternative description of the image.</p>\n<p>This text is used by Assistive Technology (AT) like screen readers to\ndescribe the image to users with visual impairments.</p>\n<p>When the image is wrapped in a <a href=\"/en-US-v0.14.1/reference/model/figure/\"><code>figure</code></a>, use this parameter\nrather than the <a href=\"/en-US-v0.14.1/reference/model/figure/#parameters-alt\">figure's <code>alt</code> parameter</a> to describe the\nimage. The only exception to this rule is when the image and the other\ncontents in the figure form a single semantic unit. In this case, use\nthe figure's <code>alt</code> parameter to describe the entire composition and do\nnot use this parameter.</p>\n<p>You can learn how to write good alternative descriptions in the\n<a href=\"/en-US-v0.14.1/guides/accessibility/#textual-representations\">Accessibility Guide</a>.</p>"}],"types":["none","str"],"strings":[],"default":"<code><span class=\"typ-key\">none</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"page","details":[{"kind":"html","content":"<p>The page number that should be embedded as an image. This attribute only\nhas an effect for PDF files.</p>"}],"types":["int"],"strings":[],"default":"<code><span class=\"typ-num\">1</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"fit","details":[{"kind":"html","content":"<p>How the image should adjust itself to a given area (the area is defined\nby the <code>width</code> and <code>height</code> fields). Note that <code>fit</code> doesn't visually\nchange anything if the area's aspect ratio is the same as the image's\none.</p>"},{"kind":"example","content":{"body":"<div class=\"previewed-code\"><pre><code><span class=\"typ-key\">#</span><span class=\"typ-key\">set</span> <span class=\"typ-func\">page</span><span class=\"typ-punct\">(</span>width<span class=\"typ-punct\">:</span> <span class=\"typ-num\">300pt</span><span class=\"typ-punct\">,</span> height<span class=\"typ-punct\">:</span> <span class=\"typ-num\">50pt</span><span class=\"typ-punct\">,</span> margin<span class=\"typ-punct\">:</span> <span class=\"typ-num\">10pt</span><span class=\"typ-punct\">)</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">image</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;tiger.jpg&quot;</span><span class=\"typ-punct\">,</span> width<span class=\"typ-punct\">:</span> <span class=\"typ-num\">100%</span><span class=\"typ-punct\">,</span> fit<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;cover&quot;</span><span class=\"typ-punct\">)</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">image</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;tiger.jpg&quot;</span><span class=\"typ-punct\">,</span> width<span class=\"typ-punct\">:</span> <span class=\"typ-num\">100%</span><span class=\"typ-punct\">,</span> fit<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;contain&quot;</span><span class=\"typ-punct\">)</span>\n<span class=\"typ-func\">#</span><span class=\"typ-func\">image</span><span class=\"typ-punct\">(</span><span class=\"typ-str\">&quot;tiger.jpg&quot;</span><span class=\"typ-punct\">,</span> width<span class=\"typ-punct\">:</span> <span class=\"typ-num\">100%</span><span class=\"typ-punct\">,</span> fit<span class=\"typ-punct\">:</span> <span class=\"typ-str\">&quot;stretch&quot;</span><span class=\"typ-punct\">)</span>\n</code></pre><div class=\"preview\"><img src=\"/en-US-v0.14.1/assets/a194706a6a99674a7fb55f288a8631c6-0.png\" alt=\"Preview page 1\"><img src=\"/en-US-v0.14.1/assets/a194706a6a99674a7fb55f288a8631c6-1.png\" alt=\"Preview page 2\"><img src=\"/en-US-v0.14.1/assets/a194706a6a99674a7fb55f288a8631c6-2.png\" alt=\"Preview page 3\"></div></div>","title":null}}],"types":["str"],"strings":[{"string":"cover","details":"<p>The image should completely cover the area (preserves aspect ratio by\ncropping the image only horizontally or vertically). This is the\ndefault.</p>"},{"string":"contain","details":"<p>The image should be fully contained in the area (preserves aspect\nratio; doesn't crop the image; one dimension can be narrower than\nspecified).</p>"},{"string":"stretch","details":"<p>The image should be stretched so that it exactly fills the area, even if\nthis means that the image will be distorted (doesn't preserve aspect\nratio and doesn't crop the image).</p>"}],"default":"<code><span class=\"typ-str\">&quot;cover&quot;</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"scaling","details":[{"kind":"html","content":"<p>A hint to viewers how they should scale the image.</p>\n<p>When set to <code><span class=\"typ-key\">auto</span></code>, the default is left up to the viewer. For PNG\nexport, Typst will default to smooth scaling, like most PDF and SVG\nviewers.</p>\n<p><em>Note:</em> The exact look may differ across PDF viewers.</p>"}],"types":["auto","str"],"strings":[{"string":"smooth","details":"<p>Scale with a smoothing algorithm such as bilinear interpolation.</p>"},{"string":"pixelated","details":"<p>Scale with nearest neighbor or a similar algorithm to preserve the\npixelated look of the image.</p>"}],"default":"<code><span class=\"typ-key\">auto</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true},{"name":"icc","details":[{"kind":"html","content":"<p>An ICC profile for the image.</p>\n<p>ICC profiles define how to interpret the colors in an image. When set\nto <code><span class=\"typ-key\">auto</span></code>, Typst will try to extract an ICC profile from the image.</p>"}],"types":["auto","str","bytes"],"strings":[],"default":"<code><span class=\"typ-key\">auto</span></code>","positional":false,"named":true,"required":false,"variadic":false,"settable":true}],"returns":["content"],"scope":[{"path":["image"],"name":"decode","title":"Decode Image","keywords":[],"oneliner":"Decode a raster or vector graphic from bytes or a string.","element":false,"contextual":false,"deprecationMessage":"`image.decode` is deprecated, directly pass bytes to `image` instead","deprecationUntil":"0.15.0","details":[{"kind":"html","content":"<p>Decode a raster or vector graphic from bytes or a string.</p>"}],"self":false,"params":[{"name":"data","details":[{"kind":"html","content":"<p>The data to decode as an image. Can be a string for SVGs.</p>"}],"types":["str","bytes"],"strings":[],"default":null,"positional":true,"named":false,"required":true,"variadic":false,"settable":false},{"name":"format","details":[{"kind":"html","content":"<p>The image's format. Detected automatically by default.</p>"}],"types":["auto","str","dictionary"],"strings":[{"string":"png","details":"<p>Raster format for illustrations and transparent graphics.</p>"},{"string":"jpg","details":"<p>Lossy raster format suitable for photos.</p>"},{"string":"gif","details":"<p>Raster format that is typically used for short animated clips. Typst can\nload GIFs, but they will become static.</p>"},{"string":"webp","details":"<p>Raster format that supports both lossy and lossless compression.</p>"},{"string":"svg","details":"<p>The vector graphics format of the web.</p>"},{"string":"pdf","details":"<p>High-fidelity document and graphics format, with focus on exact\nreproduction in print.</p>"}],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false},{"name":"width","details":[{"kind":"html","content":"<p>The width of the image.</p>"}],"types":["auto","relative"],"strings":[],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false},{"name":"height","details":[{"kind":"html","content":"<p>The height of the image.</p>"}],"types":["auto","relative","fraction"],"strings":[],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false},{"name":"alt","details":[{"kind":"html","content":"<p>A text describing the image.</p>"}],"types":["none","str"],"strings":[],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false},{"name":"fit","details":[{"kind":"html","content":"<p>How the image should adjust itself to a given area.</p>"}],"types":["str"],"strings":[{"string":"cover","details":"<p>The image should completely cover the area (preserves aspect ratio by\ncropping the image only horizontally or vertically). This is the\ndefault.</p>"},{"string":"contain","details":"<p>The image should be fully contained in the area (preserves aspect\nratio; doesn't crop the image; one dimension can be narrower than\nspecified).</p>"},{"string":"stretch","details":"<p>The image should be stretched so that it exactly fills the area, even if\nthis means that the image will be distorted (doesn't preserve aspect\nratio and doesn't crop the image).</p>"}],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false},{"name":"scaling","details":[{"kind":"html","content":"<p>A hint to viewers how they should scale the image.</p>"}],"types":["auto","str"],"strings":[{"string":"smooth","details":"<p>Scale with a smoothing algorithm such as bilinear interpolation.</p>"},{"string":"pixelated","details":"<p>Scale with nearest neighbor or a similar algorithm to preserve the\npixelated look of the image.</p>"}],"default":null,"positional":false,"named":true,"required":false,"variadic":false,"settable":false}],"returns":["content"],"scope":[]}]}}}