1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-01-08 10:45:04 +02:00
imgproxy/docs/generating_the_url_advanced.md

236 lines
7.8 KiB
Markdown
Raw Normal View History

2018-10-04 14:59:57 +02:00
# Generating the URL (Advanced)
2018-10-08 08:23:20 +02:00
This guide describes the advanced URL format that allows the use of all the imgproxy features. Read our [Generating the URL (Basic)](./generating_the_url_basic.md) guide to learn about the _basic_ URL format that is compatible with imgproxy 1.x.
2018-10-04 14:59:57 +02:00
### Format definition
The advanced URL should contain the signature, processing options, and encoded source URL, like this:
```
/%signature/%processing_options/%encoded_url.%extension
```
Check out the [example](#example) at the end of this guide.
#### Signature
2018-10-08 08:23:20 +02:00
Signature protects your URL from being altered by an attacker. It is highly recommended to sign imgproxy URLs in production.
2018-10-04 14:59:57 +02:00
2018-10-08 08:23:20 +02:00
Once you set up your [URL signature](./configuration.md#url-signature), check out the [Signing the URL](./signing_the_url.md) guide to know how to sign your URLs. Otherwise, use any string here.
2018-10-04 14:59:57 +02:00
#### Processing options
Processing options should be specified as URL parts divided by slashes (`/`). Processing option has the following format:
```
%option_name:%argument1:%argument2:...:argumentN
```
2018-10-08 08:23:20 +02:00
The list of processing options does not define imgproxy's processing pipeline. Instead, imgproxy already comes with a specific, built-in image processing pipeline for the maximum performance. Read more about it in the [About processing pipeline](./about_processing_pipeline.md) guide.
2018-10-04 14:59:57 +02:00
imgproxy supports the following processing options:
##### Resize
2018-10-25 21:56:08 +02:00
```
resize:%resizing_type:%width:%height:%enlarge
rs:%resizing_type:%width:%height:%enlarge
```
2018-10-04 14:59:57 +02:00
2018-10-08 08:23:20 +02:00
Meta-option that defines the [resizing type](#resizing-type), [width](#width), [height](#height), and [enlarge](#enlarge). All arguments are optional and can be omited to use their default values.
2018-10-04 14:59:57 +02:00
##### Size
2018-10-25 21:56:08 +02:00
```
size:%width:%height:%enlarge
s:%width:%height:%enlarge
```
2018-10-04 14:59:57 +02:00
2018-10-08 08:23:20 +02:00
Meta-option that defines the [width](#width), [height](#height), and [enlarge](#enlarge). All arguments are optional and can be omited to use their default values.
2018-10-04 14:59:57 +02:00
##### Resizing type
2018-10-25 21:56:08 +02:00
```
resizing_type:%resizing_type
rt:%resizing_type
```
2018-10-04 14:59:57 +02:00
Defines how imgproxy will resize the source image. Supported resizing types are:
2018-10-08 08:23:20 +02:00
* `fit`: resizes the image while keeping aspect ratio to fit given size;
* `fill`: resizes the image while keeping aspect ratio to fill given size and cropping projecting parts;
* `crop`: crops the image to a given size.
2018-10-04 14:59:57 +02:00
Default: `fit`
##### Width
2018-10-25 21:56:08 +02:00
```
width:%width
w:%width
```
2018-10-04 14:59:57 +02:00
2018-10-08 08:23:20 +02:00
Defines the width of the resulting image. When set to `0`, imgproxy will calculate the resulting width using the defined height and source aspect ratio. When set to `0` and the `crop` resizing type is used, imgproxy will use the full width of the source image.
2018-10-04 14:59:57 +02:00
Default: `0`
##### Height
2018-10-25 21:56:08 +02:00
```
height:%height
h:%height
```
2018-10-04 14:59:57 +02:00
2018-10-08 08:23:20 +02:00
Defines the height of the resulting image. When set to `0`, imgproxy will calculate resulting height using the defined width and source aspect ratio. When set to `0` and `crop` resizing type is used, imgproxy will use the full height of the source image.
2018-10-04 14:59:57 +02:00
Default: `0`
##### Enlarge
2018-10-25 21:56:08 +02:00
```
enlarge:%enlarge
el:%enlarge
```
2018-10-04 14:59:57 +02:00
If set to `0`, imgproxy will not enlarge the image if it is smaller than the given size. With any other value, imgproxy will enlarge the image.
Default: `0`
##### Gravity
2018-10-25 21:56:08 +02:00
```
gravity:%gravity
g:%gravity
```
2018-10-04 14:59:57 +02:00
When imgproxy needs to cut some parts of the image, it is guided by the gravity. The following values are supported:
2018-10-08 08:23:20 +02:00
* `no`: north (top edge);
* `so`: south (bottom edge);
* `ea`: east (right edge);
* `we`: west (left edge);
* `noea`: north-east (top-right corner);
* `nowe`: north-west (top-left corner);
* `soea`: south-east (bottom-right corner);
* `sowe`: south-west (bottom-left corner);
2018-10-08 08:23:20 +02:00
* `ce`: center;
* `sm`: smart. `libvips` detects the most "interesting" section of the image and considers it as the center of the resulting image;
* `fp:%x:%y`: focus point. `x` and `y` are floating point numbers between 0 and 1 that define the coordinates of the center of the resulting image. Treat 0 and 1 as right/left for `x` and top/bottom for `y`.
2018-10-04 14:59:57 +02:00
Default: `ce`
##### Background
2018-10-25 21:56:08 +02:00
```
background:%R:%G:%B
bg:%R:%G:%B
2018-10-04 14:59:57 +02:00
2018-10-25 21:56:08 +02:00
background:%hex_color
bg:%hex_color
```
2018-10-04 14:59:57 +02:00
2018-10-08 08:23:20 +02:00
When set, imgproxy will fill the resulting image background with the specified color. `R`, `G`, and `B` are red, green and blue channel values of the background color (0-255). `hex_color` is a hex-coded value of the color. Useful when you convert an image with alpha-channel to JPEG.
2018-10-04 14:59:57 +02:00
2018-10-08 08:23:20 +02:00
With no arguments provided, disables any background manipulations.
2018-10-04 14:59:57 +02:00
Default: disabled
##### Blur
2018-10-25 21:56:08 +02:00
```
blur:%sigma
bl:%sigma
```
2018-10-04 14:59:57 +02:00
2018-10-08 08:23:20 +02:00
When set, imgproxy will apply the gaussian blur filter to the resulting image. `sigma` defines the size of a mask imgproxy will use.
2018-10-04 14:59:57 +02:00
Default: disabled
##### Sharpen
2018-10-25 21:56:08 +02:00
```
sharpen:%sigma
sh:%sigma
```
2018-10-04 14:59:57 +02:00
2018-10-08 08:23:20 +02:00
When set, imgproxy will apply the sharpen filter to the resulting image. `sigma` the size of a mask imgproxy will use.
2018-10-04 14:59:57 +02:00
As an approximate guideline, use 0.5 sigma for 4 pixels/mm (display resolution), 1.0 for 12 pixels/mm and 1.5 for 16 pixels/mm (300 dpi == 12 pixels/mm).
Default: disabled
##### Watermark
2018-10-25 21:56:08 +02:00
```
2018-10-28 14:05:57 +02:00
watermark:%opacity:%position:%x_offset:%y_offset:%scale
wm:%opacity:%position:%x_offset:%y_offset:%scale
2018-10-25 21:56:08 +02:00
```
Puts watermark on the processed image.
* `opacity` - watermark opacity modifier. Final opacity is calculated like `base_opacity * opacity`. It's highly recommended to set this argument as `1` and adjust opacity with `IMGPROXY_WATERMARK_OPACITY` since this would optimize performance and memory usage.
* `position` - (optional) specifies the position of the watermark. Available values:
* `ce`: (default) center;
* `no`: north (top edge);
* `so`: south (bottom edge);
* `ea`: east (right edge);
* `we`: west (left edge);
* `noea`: north-east (top-right corner);
* `nowe`: north-west (top-left corner);
* `soea`: south-east (bottom-right corner);
* `sowe`: south-west (bottom-left corner);
* `re`: replicate watermark to fill the whole image;
2018-10-28 14:05:57 +02:00
* `x_offset`, `y_offset` - (optional) specify watermark offset by X and Y axes. Not applicable to `re` position;
* `scale` - (optional) floating point number that defines watermark size relative to the resulting image size. When set to `0` or omitted, watermark size won't be changed.
Default: disabled
2018-10-04 14:59:57 +02:00
##### Preset
2018-10-25 21:56:08 +02:00
```
preset:%preset_name1:%preset_name2:...:%preset_nameN
pr:%preset_name1:%preset_name2:...:%preset_nameN
```
2018-10-04 14:59:57 +02:00
2018-10-08 08:23:20 +02:00
Defines a list of presets to be used by imgproxy. Feel free to use as many presets in a single URL as you need.
2018-10-04 14:59:57 +02:00
2018-10-08 08:23:20 +02:00
Read more about presets in the [Presets](./presets.md) guide.
2018-10-04 14:59:57 +02:00
Default: empty
##### Format
2018-10-25 21:56:08 +02:00
```
format:%extension
f:%extension
ext:%extension
```
2018-10-04 14:59:57 +02:00
2018-10-08 08:23:20 +02:00
Specifies the resulting image format. Alias for [extension](#extension) URL part.
2018-10-04 14:59:57 +02:00
Default: `jpg`
#### Encoded URL
The source URL should be encoded with URL-safe Base64. The encoded URL can be split with `/` for your needs.
#### Extension
2018-10-08 08:23:20 +02:00
Extension specifies the format of the resulting image. At the moment, imgproxy supports only `jpg`, `png` and `webp`, them being the most popular and useful image formats on the Web.
2018-10-04 14:59:57 +02:00
2018-10-08 08:23:20 +02:00
The extension part can be omitted. In this case, if the format is not defined by processing options, imgproxy will use `jpg` by default. You can also [enable WebP support detection](./configuration.md#webp-support-detection) to use it as default resulting format when possible.
2018-10-04 14:59:57 +02:00
### Example
2018-10-08 08:23:20 +02:00
Signed imgproxy URL that uses `sharp` preset, resizes `http://example.com/images/curiosity.jpg` to fill `300x400` area with smart gravity without enlarging, and then converts the image to `png`:
2018-10-04 14:59:57 +02:00
```
http://imgproxy.example.com/AfrOrF3gWeDA6VOlDG4TzxMv39O7MXnF4CXpKUwGqRM/preset:sharp/resize:fill:300:400:0/gravity:sm/aHR0cDovL2V4YW1w/bGUuY29tL2ltYWdl/cy9jdXJpb3NpdHku/anBn.png
```
The same URL with shortcuts will look like this:
```
http://imgproxy.example.com/AfrOrF3gWeDA6VOlDG4TzxMv39O7MXnF4CXpKUwGqRM/pr:sharp/rs:fill:300:400:0/g:sm/aHR0cDovL2V4YW1w/bGUuY29tL2ltYWdl/cy9jdXJpb3NpdHku/anBn.png
```