注意:该中文文档为社区驱动的非官网文档,可能存在错译、漏译或过时等问题,请以官网文档 Documentation 为准,如发现错漏,也欢迎 您的贡献镜像)。Typst 非官方中文交流 QQ 群:793548390
Warning: the Chinese document is a community-driven non-official document, there may be mistranslation, omission or outdated problems, please refer to the official website documentation.
Typst 中文文档

image 元素
元素函数可以通过 set 和 show 规则进行样式自定义。

A raster or vector graphic.

Supported formats are PNG, JPEG, GIF and SVG.

Note: Work on SVG export is ongoing and there might be visual inaccuracies in the resulting PDF. Make sure to double-check embedded SVG images. If you have an issue, also feel free to report it on GitHub.

Example

#figure(
  image("molecular.jpg", width: 80%),
  caption: [
    A step in the molecular testing
    pipeline of our lab.
  ],
)
Preview

参数
参数是函数的输入,它们在函数名称后面的括号中传入。

path
str
必需参数位置参数
位置参数按顺序传入,不带名称。

Path to an image file.

format
auto str
可用 Set 规则
可以使用 Set 规则,为函数后续所有的使用设置默认参数。

The image's format. Detected automatically by default.

默认:auto

width
auto relative
可用 Set 规则
可以使用 Set 规则,为函数后续所有的使用设置默认参数。

The width of the image.

默认:auto

height
auto relative
可用 Set 规则
可以使用 Set 规则,为函数后续所有的使用设置默认参数。

The height of the image.

默认:auto

alt
none str
可用 Set 规则
可以使用 Set 规则,为函数后续所有的使用设置默认参数。

A text describing the image.

默认:none

fit
str
可用 Set 规则
可以使用 Set 规则,为函数后续所有的使用设置默认参数。

How the image should adjust itself to a given area.

默认:"cover"

定义
函数和类型可以有与其关联的定义 (成员或方法)。可以使用 "." 操作符来访问调用它们。

decode

Decode a raster or vector graphic from bytes or a string.

查看示例
#let original = read("diagram.svg")
#let changed = original.replace(
  "#2B80FF", // blue
  green.to-hex(),
)

#image.decode(original)
#image.decode(changed)
Preview

data
str bytes
必需参数位置参数
位置参数按顺序传入,不带名称。

The data to decode as an image. Can be a string for SVGs.

format

The image's format. Detected automatically by default.

width

The width of the image.

height

The height of the image.

alt

A text describing the image.

fit
str

How the image should adjust itself to a given area.