> For the complete documentation index, see [llms.txt](https://ayakaleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ayakaleaf-pro.ayaka.space/latex/zh-cn/zhi-shi-ku/113-optimising-very-large-image-files.md).

# 优化超大图像文件

过大的图像文件，或使用不合适文件格式的图像文件，都会显著延长编译过程，并可能导致编译超时。本文将介绍一些处理大图像文件以及选择合适图像文件格式的建议。

对于大型图像文件（每个都大于 1MB），我们建议将光栅图像（包括光栅 PDF 图像）调整大小，例如调整为 1200px 宽或高，以便减小文件大小。你可以使用图像处理程序来完成；或者如果你使用 ImageMagick，可以使用 [`convert` 命令](http://www.imagemagick.org/Usage/resize)。在 MacOS 上， [`sips -Z` 命令](http://lifehacker.com/5962420/batch-resize-images-quickly-in-the-os-x-terminal) 非常有用。

保存为 `.png` 也可能导致文件大小非常大： `.jpg` 通常是更节省空间的格式，适用于 *照片*. *线条绘图、曲线图和示意图* 更适合保存为 `.png` 或 `.pdf`，通常如此。 `.pdf` 图像的编译速度也可能比 `.png` 文件更快，如果它们的文件大小相近，因为这样编译过程就不需要调用 `libpng`.

对于 `.eps` 图像，我们建议将它们转换为 `.pdf`，因为 PDF 格式通常能在保持线条绘图的矢量特性的同时生成更小的文件。该 [`epstopdf` 命令](https://www.ctan.org/pkg/epstopdf) 很方便；你还需要安装 GhostScript。

如果你必须使用 `.eps` 项目中的图像，有时 `.eps` 文件会因导出它们的应用程序出现故障/配置错误而不必要地变大。你可以尝试修改导出设置；或者只用 GhostScript 重新处理该文件，并比较文件大小：

```
gs -o outputfile.eps -sDEVICE=epswrite originalfile.eps
```

如果你想在处理文档时节省一些编译/渲染时间，可以通过写入以下内容来开启“draft”模式，使编译更快 `\documentclass[draft]{…}` 到你的文档类声明中。通过不将图像渲染进 PDF（以及其他一些操作），“draft”选项通常可以帮助减少编译时间，这在处理大型文档时很有用。

你还可以为正在处理的项目中的特定部分开启/关闭图形：

```latex
\setkeys{Gin}{draft=false}
……这里的任何 \includegraphics 都会以完整效果渲染，因此
你可以检查文档这一部分中的图像……
\setkeys{Gin}{draft}
……这里的任何 \includegraphics 都只会显示为一个空白框。
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ayakaleaf-pro.ayaka.space/latex/zh-cn/zhi-shi-ku/113-optimising-very-large-image-files.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
