Browse Source

docs: Update image processing

index-subcmd
Vojtech Kral 5 years ago
parent
commit
5348e6452e
33 changed files with 32 additions and 19 deletions
  1. BIN
      docs/content/documentation/content/image-processing/01-zola.png
  2. BIN
      docs/content/documentation/content/image-processing/02-zola-manet.png
  3. BIN
      docs/content/documentation/content/image-processing/03-zola-cezanne.png
  4. +0
    -0
      docs/content/documentation/content/image-processing/04-gutenberg.jpg
  5. +0
    -0
      docs/content/documentation/content/image-processing/05-example.jpg
  6. +0
    -0
      docs/content/documentation/content/image-processing/06-example.jpg
  7. +0
    -0
      docs/content/documentation/content/image-processing/07-example.jpg
  8. +0
    -0
      docs/content/documentation/content/image-processing/08-example.jpg
  9. +29
    -16
      docs/content/documentation/content/image-processing/index.md
  10. BIN
      docs/static/processed_images/0478482c742970ac00.jpg
  11. BIN
      docs/static/processed_images/1794115ed20fc20b00.jpg
  12. BIN
      docs/static/processed_images/1cec18975099962e00.png
  13. BIN
      docs/static/processed_images/2b6a3e5a28bab1f100.jpg
  14. BIN
      docs/static/processed_images/3dba59a146f3bc0900.jpg
  15. BIN
      docs/static/processed_images/4c2ee08a8b7c98fd00.png
  16. BIN
      docs/static/processed_images/5e399fa94c88057a00.jpg
  17. BIN
      docs/static/processed_images/60097aeed903cf3b00.png
  18. BIN
      docs/static/processed_images/60327c08d512e16800.png
  19. BIN
      docs/static/processed_images/63d5c27341a9885c00.jpg
  20. BIN
      docs/static/processed_images/63fe884d13fd318d00.jpg
  21. BIN
      docs/static/processed_images/67f2ebdd806283e900.jpg
  22. BIN
      docs/static/processed_images/70513837257b310c00.jpg
  23. BIN
      docs/static/processed_images/7459e23e962c9d2f00.png
  24. BIN
      docs/static/processed_images/8b446e542d0b692d00.jpg
  25. BIN
      docs/static/processed_images/a9f5475850972f8500.png
  26. BIN
      docs/static/processed_images/ab39b603591b3e3300.jpg
  27. BIN
      docs/static/processed_images/aebd0f00cf9232d000.jpg
  28. BIN
      docs/static/processed_images/baf5a4139772f2c700.png
  29. BIN
      docs/static/processed_images/d364fb703e1e0b3200.jpg
  30. BIN
      docs/static/processed_images/d91d0751df06edce00.jpg
  31. BIN
      docs/static/processed_images/e1f961e8b8cb30b500.png
  32. BIN
      docs/static/processed_images/e690cdfaf053bbd700.jpg
  33. +3
    -3
      docs/templates/shortcodes/gallery.html

BIN
docs/content/documentation/content/image-processing/01-zola.png View File

Before After
Width: 300  |  Height: 380  |  Size: 120KB

BIN
docs/content/documentation/content/image-processing/02-zola-manet.png View File

Before After
Width: 400  |  Height: 527  |  Size: 324KB

BIN
docs/content/documentation/content/image-processing/03-zola-cezanne.png View File

Before After
Width: 491  |  Height: 400  |  Size: 357KB

docs/content/documentation/content/image-processing/gutenberg.jpg → docs/content/documentation/content/image-processing/04-gutenberg.jpg View File


docs/content/documentation/content/image-processing/example-00.jpg → docs/content/documentation/content/image-processing/05-example.jpg View File


docs/content/documentation/content/image-processing/example-01.jpg → docs/content/documentation/content/image-processing/06-example.jpg View File


docs/content/documentation/content/image-processing/example-02.jpg → docs/content/documentation/content/image-processing/07-example.jpg View File


docs/content/documentation/content/image-processing/example-03.jpg → docs/content/documentation/content/image-processing/08-example.jpg View File


+ 29
- 16
docs/content/documentation/content/image-processing/index.md View File

@@ -16,10 +16,22 @@ resize_image(path, width, height, op, quality)

- `path`: The path to the source image relative to the `content` directory in the [directory structure](./documentation/getting-started/directory-structure.md).
- `width` and `height`: The dimensions in pixels of the resized image. Usage depends on the `op` argument.
- `op`: Resize operation. This can be one of five choices: `"scale"`, `"fit_width"`, `"fit_height"`, `"fit"`, or `"fill"`.
What each of these does is explained below.
This argument is optional, default value is `"fill"`.
- `quality`: JPEG quality of the resized image, in percents. Optional argument, default value is `75`.
- `op` (_optional_): Resize operation. This can be one of:
- `"scale"`
- `"fit_width"`
- `"fit_height"`
- `"fit"`
- `"fill"`

What each of these does is explained below. The default is `"fill"`.
- `format` (_optional_): Encoding format of the resized image. May be one of:
- `"auto"`
- `"jpg"`
- `"png"`

The default is `"auto"`, this means the format is chosen based on input image format.
JPEG is chosen for JPEGs and other lossy formats, while PNG is chosen for PNGs and other lossless formats.
- `quality` (_optional_): JPEG quality of the resized image, in percents. Only used when encoding JPEGs, default value is `75`.

### Image processing and return value

@@ -29,7 +41,7 @@ Zola performs image processing during the build process and places the resized i
static/processed_images/
```

Resized images are JPEGs. Filename of each resized image is a hash of the function arguments,
Filename of each resized image is a hash of the function arguments,
which means that once an image is resized in a certain way, it will be stored in the above directory and will not
need to be resized again during subsequent builds (unless the image itself, the dimensions, or other arguments are changed).
Therefore, if you have a large number of images, they will only need to be resized once.
@@ -40,14 +52,14 @@ The function returns a full URL to the resized image.

The source for all examples is this 300 × 380 pixels image:

![gutenberg](gutenberg.jpg)
![zola](01-zola.png)

### **`"scale"`**
Simply scales the image to the specified dimensions (`width` & `height`) irrespective of the aspect ratio.

`resize_image(..., width=150, height=150, op="scale")`

{{ resize_image(path="documentation/content/image-processing/gutenberg.jpg", width=150, height=150, op="scale") }}
{{ resize_image(path="documentation/content/image-processing/01-zola.png", width=150, height=150, op="scale") }}

### **`"fit_width"`**
Resizes the image such that the resulting width is `width` and height is whatever will preserve the aspect ratio.
@@ -55,7 +67,7 @@ The source for all examples is this 300 × 380 pixels image:

`resize_image(..., width=100, op="fit_width")`

{{ resize_image(path="documentation/content/image-processing/gutenberg.jpg", width=100, height=0, op="fit_width") }}
{{ resize_image(path="documentation/content/image-processing/01-zola.png", width=100, height=0, op="fit_width") }}

### **`"fit_height"`**
Resizes the image such that the resulting height is `height` and width is whatever will preserve the aspect ratio.
@@ -63,7 +75,7 @@ The source for all examples is this 300 × 380 pixels image:

`resize_image(..., height=150, op="fit_height")`

{{ resize_image(path="documentation/content/image-processing/gutenberg.jpg", width=0, height=150, op="fit_height") }}
{{ resize_image(path="documentation/content/image-processing/01-zola.png", width=0, height=150, op="fit_height") }}

### **`"fit"`**
Like `"fit_width"` and `"fit_height"` combined.
@@ -72,7 +84,7 @@ The source for all examples is this 300 × 380 pixels image:

`resize_image(..., width=150, height=150, op="fit")`

{{ resize_image(path="documentation/content/image-processing/gutenberg.jpg", width=150, height=150, op="fit") }}
{{ resize_image(path="documentation/content/image-processing/01-zola.png", width=150, height=150, op="fit") }}

### **`"fill"`**
This is the default operation. It takes the image's center part with the same aspect ratio as the `width` & `height` given and resizes that
@@ -80,7 +92,7 @@ The source for all examples is this 300 × 380 pixels image:

`resize_image(..., width=150, height=150, op="fill")`

{{ resize_image(path="documentation/content/image-processing/gutenberg.jpg", width=150, height=150, op="fill") }}
{{ resize_image(path="documentation/content/image-processing/01-zola.png", width=150, height=150, op="fill") }}


## Using `resize_image` in markdown via shortcodes
@@ -96,11 +108,11 @@ The examples above were generated using a shortcode file named `resize_image.htm

## Creating picture galleries

The `resize_image()` can be used multiple times and/or in loops as it is designed to handle this efficiently.
The `resize_image()` can be used multiple times and/or in loops. It is designed to handle this efficiently.

This can be used along with `assets` [page metadata](./documentation/templates/pages-sections.md) to create picture galleries.
The `assets` variable holds paths to all assets in the directory of a page with resources
(see [Assets colocation](./documentation/content/overview.md#assets-colocation)): if you have files other than images you
(see [assets colocation](./documentation/content/overview.md#assets-colocation)): if you have files other than images you
will need to filter them out in the loop first like in the example below.

This can be used in shortcodes. For example, we can create a very simple html-only clickable
@@ -108,7 +120,7 @@ picture gallery with the following shortcode named `gallery.html`:

```jinja2
{% for asset in page.assets %}
{% if asset is ending_with(".jpg") %}
{% if asset is matching("[.](jpg|png)$") %}
<a href="{{ get_url(path=asset) }}">
<img src="{{ resize_image(path=asset, width=240, height=180, op="fill") }}" />
</a>
@@ -117,7 +129,8 @@ picture gallery with the following shortcode named `gallery.html`:
{% endfor %}
```

As you can notice, we didn't specify an `op` argument, which means it'll default to `"fill"`. Similarly, the JPEG quality will default to `75`.
As you can notice, we didn't specify an `op` argument, which means it'll default to `"fill"`. Similarly, the format will default to
`"auto"` (choosing PNG or JPEG as appropriate) and the JPEG quality will default to `75`.

To call it from a markdown file, simply do:

@@ -130,5 +143,5 @@ Here is the result:
{{ gallery() }}

<small>
Image attribution: example-01: Willi Heidelbach, example-02: Daniel Ullrich, others: public domain.
Image attribution: Public domain, except: _06-example.jpg_: Willi Heidelbach, _07-example.jpg_: Daniel Ullrich.
</small>

BIN
docs/static/processed_images/0478482c742970ac00.jpg View File

Before After
Width: 240  |  Height: 180  |  Size: 4.5KB

BIN
docs/static/processed_images/1794115ed20fc20b00.jpg View File

Before After
Width: 240  |  Height: 180  |  Size: 18KB

BIN
docs/static/processed_images/1cec18975099962e00.png View File

Before After
Width: 240  |  Height: 180  |  Size: 55KB

BIN
docs/static/processed_images/2b6a3e5a28bab1f100.jpg View File

Before After
Width: 150  |  Height: 150  |  Size: 5.4KB

BIN
docs/static/processed_images/3dba59a146f3bc0900.jpg View File

Before After
Width: 240  |  Height: 180  |  Size: 10KB

BIN
docs/static/processed_images/4c2ee08a8b7c98fd00.png View File

Before After
Width: 150  |  Height: 150  |  Size: 29KB

BIN
docs/static/processed_images/5e399fa94c88057a00.jpg View File

Before After
Width: 240  |  Height: 180  |  Size: 12KB

BIN
docs/static/processed_images/60097aeed903cf3b00.png View File

Before After
Width: 100  |  Height: 126  |  Size: 17KB

BIN
docs/static/processed_images/60327c08d512e16800.png View File

Before After
Width: 240  |  Height: 180  |  Size: 95KB

BIN
docs/static/processed_images/63d5c27341a9885c00.jpg View File

Before After
Width: 118  |  Height: 150  |  Size: 4.4KB

BIN
docs/static/processed_images/63fe884d13fd318d00.jpg View File

Before After
Width: 100  |  Height: 126  |  Size: 3.4KB

BIN
docs/static/processed_images/67f2ebdd806283e900.jpg View File

Before After
Width: 240  |  Height: 180  |  Size: 5.1KB

BIN
docs/static/processed_images/70513837257b310c00.jpg View File

Before After
Width: 240  |  Height: 180  |  Size: 12KB

BIN
docs/static/processed_images/7459e23e962c9d2f00.png View File

Before After
Width: 150  |  Height: 150  |  Size: 29KB

BIN
docs/static/processed_images/8b446e542d0b692d00.jpg View File

Before After
Width: 118  |  Height: 150  |  Size: 4.4KB

BIN
docs/static/processed_images/a9f5475850972f8500.png View File

Before After
Width: 118  |  Height: 150  |  Size: 29KB

BIN
docs/static/processed_images/ab39b603591b3e3300.jpg View File

Before After
Width: 240  |  Height: 180  |  Size: 9.6KB

BIN
docs/static/processed_images/aebd0f00cf9232d000.jpg View File

Before After
Width: 240  |  Height: 180  |  Size: 15KB

BIN
docs/static/processed_images/baf5a4139772f2c700.png View File

Before After
Width: 118  |  Height: 150  |  Size: 29KB

BIN
docs/static/processed_images/d364fb703e1e0b3200.jpg View File

Before After
Width: 240  |  Height: 180  |  Size: 12KB

BIN
docs/static/processed_images/d91d0751df06edce00.jpg View File

Before After
Width: 150  |  Height: 150  |  Size: 5.5KB

BIN
docs/static/processed_images/e1f961e8b8cb30b500.png View File

Before After
Width: 240  |  Height: 180  |  Size: 106KB

BIN
docs/static/processed_images/e690cdfaf053bbd700.jpg View File

Before After
Width: 240  |  Height: 180  |  Size: 15KB

+ 3
- 3
docs/templates/shortcodes/gallery.html View File

@@ -1,7 +1,7 @@
{% for asset in page.assets -%}
{%- if asset is ending_with(".jpg") -%}
<a href="{{ get_url(path=asset) | safe }}">
<img src="{{ resize_image(path=asset, width=240, height=180, op="fill") | safe }}" />
{%- if asset is matching("[.](jpg|png)$") -%}
<a href="{{ get_url(path=asset) | safe }}" target="_blank">
<img src="{{ resize_image(path=asset, width=240, height=180, op="fill", format="auto") | safe }}" />
</a>
&ensp;
{%- endif %}


Loading…
Cancel
Save