图片与视频

添加图片的sphinx说明:http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html

图片

图片原文件统一存储在引用文档所在的同级目录文件夹下。

显示图片直接使用 imagefigure 指令,无特殊情况的话我们书籍图片要求使用居中方式显示, 还需要添加 alt 选项指定图片的描述,用于网站中使用,以便图片加载失败时显示文字。

不要使用bmp图片 ,bmp图片在生成pdf的时候会丢失,所以不要使用bmp格式的图片。

Note

推荐使用 figure 命令插入图片。

figure 命令

figure 添加图片时可以使用标题与legend。一般在使用时要加入引用。 语法如下:

如 :numref:`fig_qgis_figure220` 。

.. _fig_qgis_figure220:
.. figure: ./logo.png
   :alt: logo
   :align: center

   图片的标题

效果:

如图 fig_qgis_figure220

logo

图片的标题

image 命令:

语法:

.. image:: ../../_images/logo.png
   :align: center
   :alt: 野火logo

以下的图片显示方式是word自动转换的结果,使用这种方式无法以居中形式显示图片,所以我们要修改。

它的原理是使用“||”类似宏的方式替换指令,使rst源码看起来更简洁,但不能居中显示。

语法:

|logo|,使用"|宏名|"的形式替换文字。

.. |logo| image:: ./logo.png

图片还可以使用 width、heigh、scale等参数,但不推荐使用,设置过width、height参数的图片, 在页面可以点击查看原图。

语法:

.. image:: ./logo.png
   :align: center
   :width: 5.63529in
   :height: 0.97222in

使用image

.. image:: picture.jpeg
   :class: class-name
       :name: name
   :height: 100 px(长度)
   :width: 200 px (长度或者百分比)
   :scale: 50 % (百分比,百分号可省略)
   :alt: alternate text
   :align: right
       :target: https://www.baidu.com

align可选top,middle,bottom,left,center,right

target使得图片可点击跳转。

scale表示等比例伸缩(放大或者缩小)

Important

scale需要和width或者height(或者2者)一起使用。

使用figure

.. figure:: picture.png
   :figwidth: 200 px (长度或者百分比)
   :scale: 50 %
       :align: center
       :figclass: figure-class
   :alt: map to buried treasure

    +---------------------------+
    |        figure             |
    |                           |
    |<------ figwidth --------->|
    |                           |
    |  +---------------------+  |
    |  |     image           |  |
    |  |                     |  |
    |  |<--- width --------->|  |
    |  +---------------------+  |
    |                           |
    |The figure's caption should|
    |wrap at this width.        |
    +---------------------------+

figure相当于一个画布(类似于html中的一个div或者一个canvas), 它对处于其内的内容进行样式统一管理。相比image可以包含除图片外的更多内容。

figure支持image的所有指令选项参数,除了align在figure中指示整个画布的对齐方式。 且它只能选择为left,center,right。

Important

和image一致,要使得scale(这里是对整个画布作用)起作用需要和figwidth一起使用