Skip to content

Commit 23a93fc

Browse files
committed
Add guide to putting images in the corpus
1 parent b9fdf13 commit 23a93fc

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

source/meta/images-guide.txt

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
:orphan:
2+
3+
=============
4+
Adding Images
5+
=============
6+
7+
.. note::
8+
9+
This guide is advisory, and its suggestions do not necessarily apply
10+
to every situation.
11+
12+
Without Giza (Recommended)
13+
--------------------------
14+
15+
Adding an SVG
16+
~~~~~~~~~~~~~
17+
18+
Whenever possible, you should publish diagrams in SVG form. This
19+
provides a crisp image at any screen resolution with a small file
20+
size.
21+
22+
First install `mut <https://github.com/mongodb/mut>`_,
23+
`Inkscape <http://inkscape.org/>`_, and
24+
`svgo <https://github.com/svg/svgo>`_.
25+
26+
Place your SVG in ``source/images/``. If you named your SVG
27+
``foo.svg``, then run the following:
28+
29+
.. code-block:: sh
30+
31+
mut-images foo.svg
32+
33+
This will generate ``foo.bakedsvg.svg``. This *baked* SVG file
34+
contains no text: to prevent users from needing to download any fonts,
35+
``mut-images`` transforms all text elements into paths. It then uses
36+
``svgo`` to minify the resulting SVG file.
37+
38+
Create a ``source/images/foo.rst`` file with contents such as the
39+
following:
40+
41+
.. code-block:: rst
42+
43+
.. figure:: /images/foo.bakedsvg.svg
44+
:alt: An example image.
45+
:figwidth: 500px
46+
47+
Check in and commit all three files.
48+
49+
Adding a PNG
50+
~~~~~~~~~~~~
51+
52+
Not all images start their life as an SVG. The process is less refined
53+
for adding these files, but in general keep the resolution under two times
54+
the display width.
55+
56+
For example, if you want to display an image as 500px wide, the image
57+
itself should not be wider than 1000px.
58+
59+
.. note::
60+
61+
The MongoDB Documentation Project does not currently have a best
62+
practice for handling very large (>1080p) files or photographic
63+
content.
64+
65+
It may make sense to use
66+
`mozjpeg <https://github.com/mozilla/mozjpeg>`_ if you need lossy
67+
compression; `imagemagick <http://imagemagick.org/>`_ to resize images;
68+
and a `Ninja <http://ninja-build.org/>`_ file to put the pieces
69+
together.
70+
71+
The default ``libpng`` encoder does not create optimal PNG files, so
72+
install `zopflipng <https://github.com/google/zopfli>`_. To compress a
73+
PNG, use the following template:
74+
75+
.. code-block:: sh
76+
77+
zopflipng -m <input.png> <output.png>
78+
79+
This may take several minutes, as the ``-m`` option requests a
80+
brute-force search for optimal compression parameters.
81+
82+
Place the output PNG in ``source/images/``, and create a
83+
``source/images/foo.rst`` file with contents such as the following:
84+
85+
.. code-block:: rst
86+
87+
.. figure:: /images/foo.png
88+
:alt: An example image.
89+
:figwidth: 500px
90+
91+
With Giza
92+
---------
93+
94+
Some MongoDB documentation projects use Giza's image generation. This
95+
can be effective when you need images rendered at different sizes
96+
for different output formats.
97+
98+
It has the following disadvantages:
99+
100+
* Giza only accepts SVGs: you must embed raster files inside of an SVG,
101+
* Giza invokes inkscape for each input file, and
102+
* Reliability problems. There was one instance where giza generated
103+
some images sans any text.
104+
105+
Giza looks for the path listed in ``system.files.data.files`` within
106+
``config/build_conf.yaml`` for a manifest containing image metadata.
107+
108+
The image metadata is a YAML list of documents such as the following:
109+
110+
.. code-block:: yaml
111+
112+
name: opsmanager-large
113+
alt: "A highly available deployment uses horizontal scaling of the application database and backup blockstore database, as well as multiple backup daemons."
114+
output:
115+
- type: print
116+
tag: 'print'
117+
dpi: 300
118+
width: 2100
119+
- type: web
120+
dpi: 72
121+
width: 700
122+
123+
From this example, Giza will generate the following files in the build
124+
directory:
125+
126+
* ``/source/images/opsmanager-large.rst``
127+
* ``/source/images/opsmanager-large.png``
128+
* ``/source/images/opsmanager-large-print.png``

0 commit comments

Comments
 (0)