File: usage.rst

package info (click to toggle)
thumbor 7.7.7-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 40,556 kB
  • sloc: xml: 295,435; python: 18,673; ansic: 1,479; makefile: 360; sh: 27
file content (282 lines) | stat: -rw-r--r-- 10,253 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
Usage
=====

Using thumbor is really straightforward. thumbor offers one endpoint for
retrieving the image and a very similar endpoint to retrieve metadata.

Image Endpoint
--------------

.. code::

   /hmac/trim/AxB:CxD/(adaptive-)(full-)fit-in/-Ex-F/HALIGN/VALIGN/smart/filters:FILTERNAME(ARGUMENT):FILTERNAME(ARGUMENT)/*IMAGE-URI*

-  hmac is the signature that ensures :doc:`security` ;
-  trim removes surrounding space in images using top-left pixel color
   unless specified otherwise;
-  AxB:CxD means manually crop the image at left-top point AxB and
   right-bottom point CxD;
-  fit-in means that the generated image should not be auto-cropped and
   otherwise just fit in an imaginary box specified by ExF. If a full
   fit-in is specified, then the largest size is used for cropping (width
   instead of height, or the other way around). If adaptive fit-in is
   specified, it inverts requested width and height if it would get a better
   image definition;
-  -Ex-F means resize the image to be ExF of width per height size. The
   minus signs mean flip horizontally and vertically;
-  HALIGN is horizontal alignment of crop;
-  VALIGN is vertical alignment of crop;
-  smart means using smart detection of focal points;
-  filters can be applied sequentially to the image before returning;
-  *IMAGE-URI* is the encoded URI for the image you want resized.

Trim
~~~~

Removing surrounding space in images can be done using the trim option.

Unless specified trim assumes the top-left pixel color and no tolerance
(more on tolerance below).

To use it, just add a ``/trim`` part to your URL.

If you need to specify the orientation from where to get the pixel
color, just use ``/trim:top-left`` for the top-left pixel color or
``/trim:bottom-right`` for the bottom-right pixel color.

Trim also supports color tolerance. The euclidean distance between the
colors of the reference pixel and the surrounding pixels is used. If the
distance is within the tolerance they'll get trimmed. For a RGB image
the tolerance would be within the range 0-442.

Manual Crop
~~~~~~~~~~~

The manual crop is entirely optional. This is very useful for
applications that provide custom real-time cropping capabilities to
their users.

The manual crop part of the url takes two points as arguments, separated
by a colon. The first point is the left-top point of the cropping
rectangle. The second point is the right-bottom point.

This crop is performed before the rest of the operations, so it can be
used as a *prepare* step before resizing and smart-cropping. It is
**very** useful when you just need to get that celebrity face on a big
picture full of people, as an example.

Fit in
~~~~~~

The fit-in argument specifies that the image should not be auto-cropped
and auto-resized to be **EXACTLY** the specified size, and should be fit in
an imaginary box of "E" width and "F" height, instead.

Consider an image of :math:`800px` x :math:`600px`, and a fit of :math:`300px` x :math:`200px`. This is
how thumbor would resize it:

.. image:: images/vertical-fit-in.png
    :alt: An image in a vertical fit-in

Consider an image of :math:`400px` x :math:`600px`, and a fit of :math:`300px` x :math:`200px`. This is
how thumbor would resize it:

.. image:: images/horizontal-fit-in.png
    :alt: An image in a horizontal fit-in

This is very useful when you need to fit an image somewhere, but you
have no idea about the original image dimensions.

If a full fit-in is used, instead of using the largest size for cropping
it uses the smallest one, so in the above scenarios:

For the image of :math:`800px` x :math:`600px`, with a full fit-in of :math:`300px` x :math:`200px`, we
would get an image of :math:`300px` x :math:`225px`.

For the image of :math:`400px` x :math:`600px`, with a full fit-in of :math:`300px` x :math:`200px`, we
would get an image of :math:`300px` x :math:`450px`.

.. TODO: Add adaptive fit in information here

Image Size
~~~~~~~~~~

The image size argument specifies the size of the image that will be
returned by the service. Thumbor uses smart :doc:`crop_and_resize_algorithms`

If you omit one of the dimensions or use zero as a value (as in :math:`300x`,
:math:`300x0`, :math:`x200`, :math:`0x200`, and so on), Thumbor will determine that dimension as
to be proportional to the original image. Say you have an :math:`800x600` image
and ask for a :math:`400x0` image. Thumbor will infer that since :math:`400` is half of
:math:`800`, then the height you are looking for is half of :math:`600`, which is :math:`300px`.

If you use :math:`0x0`, Thumbor will use the original size of the image and thus
won't do any cropping or resizing.

If you specify one of the dimensions as the string "orig" (as in
:math:`origx100`, :math:`100xorig`, :math:`origxorig`), thumbor will interpret that you want
that dimension to remain the same as in the original image. Consider an
image of :math:`800x600`. If you ask for a :math:`300xorig` version of it, thumbor will
interpret that you want a :math:`300x600` image. If you instead ask for a
:math:`origx300` version, thumbor will serve you an :math:`800x300` image.

If you use :math:`origxorig`, Thumbor will use the original size of the image
and thus won't do any cropping or resizing.

**The default value (in case it is omitted) for this option is to use
proportional size (0) to the original image.**

Horizontal Align
~~~~~~~~~~~~~~~~

As was explained above, unless the image is of the same proportion as
the desired size, some cropping will need to occur.

The horizontal align option controls where the cropping will occur if
some width needs to be trimmed (unless some feature detection occurs -
more on that later).

So, if we need to trim :math:`300px` of the width and the current horizontal
align is "left", then we'll trim 0px of the left of the image and :math:`300px`
of the right side of the image.

The possible values for this option are:

-  ``left`` - only trims the right side;
-  ``center`` - trims half of the width from the left side and half from the
   right side;
-  ``right`` - only trims the left side.

It is important to notice that this option is useless in case of the
image being vertically trimmed, since Thumbor's cropping algorithm only
crops in one direction.

**The default value (in case it is omitted) for this option is
"center".**

Vertical Align
~~~~~~~~~~~~~~

The vertical align option is analogous to the horizontal one, except
that it controls height trimming.

So, if we need to trim :math:`300px` of the height and the current vertical
align is "top", then we'll trim :math:`0px` of the top of the image and :math:`300px` of
the bottom side of the image.

The possible values for this option are:

-  ``top`` - only trims the bottom;
-  ``middle`` - trims half of the height from the top and half from the
   bottom;
-  ``bottom`` - only trims the top.

It is important to notice that this option is useless in case of the
image being horizontally trimmed, since Thumbor's cropping algorithm
only crops in one direction.

**The default value (in case it is omitted) for this option is
"middle".**

Smart Cropping
~~~~~~~~~~~~~~

Thumbor uses some very advanced techniques for obtaining important
points of the image (referred to as Focal Points in the rest of this
documentation).

Even though Thumbor comes with facial recognition of Focal Points as
well as feature recognition, you can easily implement your own detectors
as you'll see further in the docs.

There's not much to this option, since we'll cover it in the :doc:`detection_algorithms`
page. If you use it in the url, smart cropping will be
performed and will override both horizontal and vertical alignments if
it finds any Focal Points.

**The default value (in case it is omitted) for this option is not to
use smart cropping.**

Filters
~~~~~~~

Thumbor allows for usage of a filter pipeline that will be applied
sequentially to the image. Filters are covered in the
:doc:`filters` page if you want to know more.

To use filters add a ``filters:`` part in your URL. Filters are like
function calls ``filter_name(argument, argument2, etc)`` and are
separated using the ``:`` character, like ``filters:filter_name():other_filter()``.

Image URI
~~~~~~~~~

This is the image URI. The format of this option depends heavily on the
image loader you are using. Thumbor comes pre-packaged with an HTTP
loader and a Filesystem loader.

.. TODO: Add all the built-in loaders here.

If you use the HTTP loader, this option corresponds to the image
complete URI.

If you use the Filesystem loader, this option corresponds to the path of
the image from the images root.

You can learn more about the loaders in the :doc:`image_loader` page.

.. _usage-metadata-endpoint:

Metadata Endpoint
-----------------

The metadata endpoint has **ALL** the options that the image one has,
but instead of actually performing the operations in the image, it just
simulates the operations.

Since it has the same options as the other endpoint, we won't repeat all
of them. To use the metadata endpoint, just add a */meta* in the
beginning of the url.

Say we have the following crop URL:

http://my-server.thumbor.org/unsafe/-300x-200/left/top/smart/path/to/my/nice/image.jpg

If we want the metadata on what thumbor would do, just change the url to
be

http://my-server.thumbor.org/unsafe/meta/-300x-200/left/top/smart/path/to/my/nice/image.jpg

After the processing is finished, thumbor will return a json object
containing metadata on the image and the operations that would have been
performed.

The json looks like this:

.. code:: javascript

    {
        thumbor: {
            source: {
                url: "path/to/my/nice/image.jpg",
                width: 800,
                height: 600
            },
            operations: [
                {
                    type: "crop",
                    left: 10,
                    top: 10,
                    right: 300,
                    bottom: 200
                },
                {
                    type: "resize",
                    width: 300,
                    height: 200
                },
                { type: "flip_horizontally" },
                { type: "flip_vertically" }
            ]
        }
    }