image
Element
Element functions can be customized with set
and show
rules.
set
and show
rules.ラスターまたはベクター画像。
画像をfigure
で囲むことで、番号とキャプションを与えることができます。
ほとんどの要素と同様に、画像はデフォルトでは ブロックレベル であるため、隣接する段落に統合されることはありません。
画像を強制的にインラインにするには、box
の中に入れてください。
例
#figure(
image("molecular.jpg", width: 80%),
caption: [
A step in the molecular testing
pipeline of our lab.
],
)

引数
Parameters are the inputs to a function. They are specified in parentheses after the function name.
source
A path to an image file or raw bytes making up an image in one of the supported formats.
Bytes can be used to specify raw pixel data in a row-major, left-to-right, top-to-bottom format.
View example
#let original = read("diagram.svg")
#let changed = original.replace(
"#2B80FF", // blue
green.to-hex(),
)
#image(bytes(original))
#image(bytes(changed))

format
Settable
Settable parameters can be customized for all following uses of the function with a set
rule.
set
rule.画像のフォーマット。
By default, the format is detected automatically. Typically, you thus
only need to specify this when providing raw bytes as the
source
(even then, Typst will try to figure out the
format automatically, but that's not always possible).
生のピクセルデータと同様にサポートされている拡張子は"png"
、"jpg"
、"gif"
、"svg"
です。
PDFの画像はまだサポートされていません。
When providing raw pixel data as the source
, you must specify a
dictionary with the following keys as the format
:
encoding
(str): The encoding of the pixel data. One of:"rgb8"
(three 8-bit channels: red, green, blue)"rgba8"
(four 8-bit channels: red, green, blue, alpha)"luma8"
(one 8-bit channel)"lumaa8"
(two 8-bit channels: luma and alpha)
width
(int): The pixel width of the image.height
(int): The pixel height of the image.
The pixel width multiplied by the height multiplied by the channel count
for the specified encoding must then match the source
data.
-
"png"
イラストや透明グラフィック用のラスターフォーマット。
-
"jpg"
写真に適した非可逆ラスターフォーマット。
-
"gif"
短いアニメーションクリップによく使われるラスターフォーマット。 TypstはGIFを読み込めるが、静止画となってしまう。
-
"svg"
Webサイトに用いられるベクターフォーマット。
Default:auto
View example
#image(
read(
"tetrahedron.svg",
encoding: none,
),
format: "svg",
width: 2cm,
)
#image(
bytes(range(16).map(x => x * 16)),
format: (
encoding: "luma8",
width: 4,
height: 4,
),
width: 2cm,
)

width
画像の幅。
Default:auto
height
画像の高さ。
Default:auto
alt
画像の説明文。
Default:none
fit
Settable
Settable parameters can be customized for all following uses of the function with a set
rule.
set
rule.与えられた領域に対して、画像をどのように調整するか。
領域は width
や height
フィールドで定義します。
領域の縦横比が画像の縦横比と同じであれば、fit
で見た目が変わらないことに注意してください。
-
"cover"
領域を完全にカバーします。 水平または垂直方向にのみ画像をトリミングすることで、アスペクト比を保持します。 これがデフォルトです。
-
"contain"
画像は領域内に完全に収まるようにします。 アスペクト比を維持して、画像を切り取らず、1つの寸法は指定より狭くします。
-
"stretch"
たとえ画像が歪むことになっても、その領域を正確に埋めるように引き伸ばします。 アスペクト比は保たれず、画像は切り取られません。
Default:"cover"
View example
#set page(width: 300pt, height: 50pt, margin: 10pt)
#image("tiger.jpg", width: 100%, fit: "cover")
#image("tiger.jpg", width: 100%, fit: "contain")
#image("tiger.jpg", width: 100%, fit: "stretch")

scaling
A hint to viewers how they should scale the image.
When set to auto
, the default is left up to the viewer. For PNG
export, Typst will default to smooth scaling, like most PDF and SVG
viewers.
Note: The exact look may differ across PDF viewers.
-
"smooth"
Scale with a smoothing algorithm such as bilinear interpolation.
-
"pixelated"
Scale with nearest neighbor or a similar algorithm to preserve the pixelated look of the image.
Default:auto
icc
An ICC profile for the image.
ICC profiles define how to interpret the colors in an image. When set
to auto
, Typst will try to extract an ICC profile from the image.
Default:auto
定義
Functions and types and can have associated definitions. These are accessed by specifying the function or type, followed by a period, and then the definition's name.
decode
`image.decode` is deprecated, directly pass bytes to `image` instead
Decode a raster or vector graphic from bytes or a string.
data
画像としてデコードするデータ。SVGの場合は文字列です。
format
画像のフォーマット。デフォルトでは自動的に検出されます。
-
"png"
イラストや透明グラフィック用のラスターフォーマット。
-
"jpg"
写真に適した非可逆ラスターフォーマット。
-
"gif"
短いアニメーションクリップによく使われるラスターフォーマット。 TypstはGIFを読み込めるが、静止画となってしまう。
-
"svg"
Webサイトに用いられるベクターフォーマット。
width
画像の幅。
height
画像の高さ。
alt
画像の説明文。
fit
与えられた領域に対して、画像をどのように調整するか。
-
"cover"
領域を完全にカバーします。 水平または垂直方向にのみ画像をトリミングすることで、アスペクト比を保持します。 これがデフォルトです。
-
"contain"
画像は領域内に完全に収まるようにします。 アスペクト比を維持して、画像を切り取らず、1つの寸法は指定より狭くします。
-
"stretch"
たとえ画像が歪むことになっても、その領域を正確に埋めるように引き伸ばします。 アスペクト比は保たれず、画像は切り取られません。
scaling
A hint to viewers how they should scale the image.
-
"smooth"
Scale with a smoothing algorithm such as bilinear interpolation.
-
"pixelated"
Scale with nearest neighbor or a similar algorithm to preserve the pixelated look of the image.