如何为使用手册准备图像

此页面对 为互联网保存图像 页面的补充。主要讨论如何为本使用手册制作图像和优化它们的大小。

目录

截图工具

如果你打算为屏幕显示的各种面板和工具进行截图,光靠 为互联网保存图像 的指引显然不够,毕竟这只能保存画布上面的图像。

因此我们要先对屏幕进行截图。根据操作系统不同,我们有几种不同的截图工具可用。

Windows

Windows has a build-in screenshot tool. It is by default on the Print Screen key. On laptops you will sometimes need to use the Fn key.

Linux

Both Gnome and KDE have decent screenshot tools showing up by default when using the Print Screen key, as well do other popular desktop environments. If, for whatever reason, you have no

ImageMagick

使用 imagemagick,输入下面的命令:

  1. import -depth 8 -dither <filename.png>

While we should minimize the amount of GIFs in the manual for a variety of accessibility reasons, you sometimes still need to make GIFs and short videos. Furthermore, GIFs are quite nice to show off features with release notes.

For making short GIFs, you can use the following programs:

  • Peek – This one has an AppImage and a very easy user-interface. Like many screenrecording programs it does show trouble on Wayland.

macOS

The Screenshot hotkey on macOS is Shift + Command + 3, according to the official apple documentation.

按用途选择合适的文件格式

不同的文件格式适合不同类型的图像。我们既要提高画质,也要减小体积,因为这样有利于互联网浏览和下载使用手册。

软件界面截图

This should use PNG, and if possible, in GIF.

以非渐变色为主的图像。

This should use PNG.

灰阶图像

These should be GIF or PNG.

渐变色较多的图像

应当使用 JPG。

透明区域较大的图像

应当使用 PNG。

The logic is the way how each of these saves colors. JPEG is ideal for photos and images with a lot of gradients because it compresses differently. However, contrasts don’t do well in JPEG. PNG does a lot better with images with sharp contrasts, while in some cases we can even have less than 256 colors, so GIF might be better.

Grayscale images, even when they have a lot of gradients variation, should be PNG. The reason is that when we use full color images, we are, depending on the image, using 3 to 5 numbers to describe those values, with each of those values having a possibility to contain any of 256 values. JPEG and other ‘lossy’ file formats use clever psychological tricks to cut back on the amount of values an image needs to show its contents. However, when we make grayscale images, we only keep track of the lightness. The lightness is only one number, that can have 256 values, making it much easier to just use GIF or PNG, instead of JPEG which could have nasty artifacts. (And, it is also a bit smaller)

要是拿不定主意,请使用 PNG。

优化图像品质和尺寸

虽然绝大多数图像编辑软件都会尽量减小文件体积,我们还可以通过其他工具来把图片变得更小。

Windows

在 Windows 下面人们经常推荐使用 IrfranView ,但本文档的作者并没有时间去鼓捣它的使用方法。

另一个选项则是 PNGCrush,参见 Linux 一节。

Linux

优化 PNG 文件

Linux 下面有多种 PNG 优化工具 可供选用。它们分为两类:有损 (按心理学原则削减数据) 和无损 (用一般方式进行压缩)。推荐使用:

PNGQuant

此 PNG 压缩工具通过一些有损技术巧妙地降低了图像使用的颜色数目。

要使用 PNGquant,前往目标文件夹,然后输入:

  1. pngquant --quality=80-100 image.png

Where image is replaced with the image file name. When you press the Enter key, a new image will appear in the folder with the compressed results. PNGQuant works for most images, but some images, like the color selectors don’t do well with it, so always double check that the resulting image looks good, otherwise try one of the following options:

PNGCrush

这是一个无损的 PNG 压缩工具。用法:

  1. pngcrush image.png imageout.png

该指令仅通过常见手段进行压缩,添加 -brute 参数后软件会使用一切可能手段进行压缩。

Optipng

这是一个无损的 PNG 压缩工具,一开始是 PNGCrush 的分支项目,可以在使用 PNGQuant 之后使用。用法:

  1. optipng image.png

where image is the filename. OptiPNG will then proceed to test several compression algorithms and overwrite the image.png file with the optimised version. You can avoid overwriting with the --out imageout.png command.

优化 GIF 文件

优化 JPEG 文件

JPEG 很难进行有效优化。这是因为它是一种 有损文件格式 ,意味着它通过心理学手段保存数据。

然而这些手段在图像具有很多强烈对比时很容易露馅,例如文字。JPEG 也不适合被反复保存。因此你必须把图像保存为无损格式用于编辑,只在输出最终结果时才用 JPEG 进行进一步压缩。

macOS

  • ImageOptim – 一个为诸如 PNGquant 和 gifski 等工具设计的图形界面。

编辑文件的元数据

个人信息有时候会不小心被嵌入到图像文件中,而有时候我们可以借助嵌入信息来辅助文件的整理记录工作。

处理元数据的工具有好几种,不同文件格式的元数据结构也不尽相同。

用于编辑元数据的最常用工具是 ExifTool ,除此之外还可以使用 ImageMagick

Windows and macOS

要下载exiftool,可 访问其网站

Linux

在 Linux 下面你还可以直接安装 exiftool。

Debian/Ubuntu

sudo apt-get install libimage-exiftool-perl

查看元数据

切换到图像文件所在的目录,然后输入:

  1. exiftool image

把 image 字段换成你需要的文件名。如果只输入 exiftool,它会把当前目录下面的文件的元数据全部输出。仔细查看某些图像的元数据,你会不时发现它们包含了作者和位置元数据。这对于隐私来说会造成一些问题,因此我们有时需要清空全部元数据。

你还可以使用 ImageMagick 的 identify 参数:

  1. identify -verbose image

清空元数据

image.png 为例,元数据的清空方式如下:

ExifTool

exiftool -all= image.png

这将清空 exiftool 所能处理的一切标签。你还可以指定移除一个单独标签:exiftool -author= image.png

OptiPNG

optipng -strip image.png 指令会清空该 PNG 文件的元数据并对其进行压缩。

ImageMagick

convert image.png –strip

提取元数据

Sometimes we want to extract metadata, like an ICC profile, before stripping everything. This is done by converting the image to the profile type:

ImageMagick’s Convert

首先把图像的 ICC 元数据进行转换并提取为一个配置文件:

  1. convert image.png image_profile.icc

然后把源文件的元数据清空,再把 ICC 配置文件信息单独重新添加回去:

  1. convert -profile image_profile.icc image.png

嵌入描述元数据

描述元数据对于屏幕阅读器的用户来说非常有用,许多网页浏览器会在没有 alt 字串的情况下通过图像的描述元数据生成它。你或许也需要嵌入色彩空间之类的信息。

ExifTool

ImageMagick

设定一组 exif 数值:

  1. convert -set exif:ImageDescription "An image description" image.png image_modified.png

设置 PNG 区块描述:

  1. convert -set Description "An image description" image.png image_modified.png

嵌入许可证元数据

嵌入许可证元数据的好处是可以永久标记某个文件的许可证。不过其他人在转载时很可能会通过 imagemagick 清空这些元数据。

使用属性

你可以使用 dcterms:license 参数把许可证信息插入到文档规定的位置。

ImageMagick

用于 GDPL:

  1. convert -set dcterms:license "GDPL 1.3+ https://www.gnu.org/licenses/fdl-1.3.txt" image.png

这将定义一项属性名并填入许可证文本。

用于 Creative Commons BY-SA 4.0:

  1. convert -set dcterms:license "CC-BY-SA-4.0 https://creativecommons.org/licenses/by-sa/4.0/" image.png

这种做法的问题是它并不符合许可证定义的规范,因此机器不能处理它们。

使用 XMP

Creative Commons 网站建议我们 使用 XMP 来定义许可证 。在 Creative Commons 网站上选取许可证时,可以要求它为你生成一个适合的 XMP 文件。

我们需要使用 面向 exiftool 的 XMP 标签

命令范例如下:

  1. exiftool -Marked=true -License="https://creativecommons.org/licenses/by-sa/4.0" -UsageTerms="This work is licensed under a <a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>." -Copyright="CC-BY-SA-NC 4.0" image.png

或者也可以这样做:

  1. exiftool -Marked=true -License="https://creativecommons.org/licenses/by-sa/4.0" -attributionURL="docs.krita.org" attributionName="kritaManual" image.png

通过 Imagemagick 的 profile 参数嵌入

首先提取元数据 (如有需要):

  1. convert image.png image_meta.xmp

对生成的文件进行修改,然后把元数据嵌回到图像:

  1. convert -profile image_meta.xmp image.png

每个 XMP 标签可以定义一个许可证。你可以在 Creative Commons 网站上为图像的元数据生成 XMP 文件。