jekyll_picture_tag 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/docs/Gemfile +4 -2
- data/docs/Gemfile.lock +14 -12
- data/docs/_config.yml +6 -10
- data/docs/devs/contributing/code.md +44 -0
- data/docs/devs/contributing/docs.md +13 -0
- data/docs/devs/contributing/index.md +15 -0
- data/docs/devs/contributing/setup.md +13 -0
- data/docs/devs/contributing/testing.md +41 -0
- data/docs/devs/index.md +7 -0
- data/docs/{releases.md → devs/releases.md} +24 -14
- data/docs/index.md +43 -27
- data/docs/users/configuration/cdn.md +35 -0
- data/docs/users/configuration/directories.md +34 -0
- data/docs/users/configuration/disable.md +24 -0
- data/docs/users/configuration/fast_build.md +28 -0
- data/docs/users/configuration/ignore_missing.md +23 -0
- data/docs/users/configuration/index.md +29 -0
- data/docs/users/configuration/kramdown_fix.md +20 -0
- data/docs/users/configuration/relative_urls.md +15 -0
- data/docs/users/configuration/suppress_warnings.md +16 -0
- data/docs/users/index.md +7 -0
- data/docs/users/installation.md +52 -0
- data/docs/users/liquid_tag/argument_reference/alternate_images.md +18 -0
- data/docs/users/liquid_tag/argument_reference/attributes.md +42 -0
- data/docs/users/liquid_tag/argument_reference/base_image.md +12 -0
- data/docs/users/liquid_tag/argument_reference/crop.md +48 -0
- data/docs/users/liquid_tag/argument_reference/link.md +16 -0
- data/docs/users/liquid_tag/argument_reference/preset.md +17 -0
- data/docs/users/liquid_tag/argument_reference/readme.md +9 -0
- data/docs/users/liquid_tag/examples.md +81 -0
- data/docs/users/liquid_tag/index.md +31 -0
- data/docs/users/notes/git_lfs.md +7 -0
- data/docs/users/notes/github_pages.md +5 -0
- data/docs/users/notes/html_attributes.md +5 -0
- data/docs/users/notes/index.md +6 -0
- data/docs/users/notes/input_checking.md +6 -0
- data/docs/users/notes/kramdown_bug.md +41 -0
- data/docs/users/notes/managing_images.md +21 -0
- data/docs/{migration.md → users/notes/migration.md} +0 -0
- data/docs/users/presets/cropping.md +61 -0
- data/docs/users/presets/default.md +23 -0
- data/docs/users/presets/examples.md +79 -0
- data/docs/users/presets/fallback_image.md +28 -0
- data/docs/users/presets/html_attributes.md +26 -0
- data/docs/users/presets/image_formats.md +21 -0
- data/docs/users/presets/image_quality.md +43 -0
- data/docs/users/presets/index.md +101 -0
- data/docs/users/presets/link_source.md +16 -0
- data/docs/users/presets/markup_formats/fragments.md +48 -0
- data/docs/users/presets/markup_formats/javascript_friendly.md +57 -0
- data/docs/users/presets/markup_formats/readme.md +43 -0
- data/docs/users/presets/markup_formats/standard_html.md +25 -0
- data/docs/users/presets/media_queries.md +36 -0
- data/docs/users/presets/nomarkdown_override.md +17 -0
- data/docs/users/presets/pixel_ratio_srcsets.md +32 -0
- data/docs/users/presets/width_height_attributes.md +34 -0
- data/docs/users/presets/width_srcsets.md +85 -0
- data/lib/jekyll_picture_tag/instructions/preset.rb +5 -1
- data/lib/jekyll_picture_tag/instructions/set.rb +5 -1
- data/lib/jekyll_picture_tag/version.rb +1 -1
- metadata +55 -14
- data/docs/_layouts/directory.html +0 -32
- data/docs/assets/style.css +0 -31
- data/docs/contributing.md +0 -109
- data/docs/example_presets.md +0 -116
- data/docs/global_configuration.md +0 -173
- data/docs/installation.md +0 -45
- data/docs/notes.md +0 -91
- data/docs/output.md +0 -63
- data/docs/presets.md +0 -391
- data/docs/usage.md +0 -157
@@ -1,173 +0,0 @@
|
|
1
|
-
---
|
2
|
-
---
|
3
|
-
# Global Configuration
|
4
|
-
|
5
|
-
**All configuration is optional**. If you are happy with the defaults, you don't have to touch a
|
6
|
-
single yaml file.
|
7
|
-
|
8
|
-
Global settings are stored under the `picture:` key in `/_config.yml`.
|
9
|
-
|
10
|
-
**Example config:**
|
11
|
-
|
12
|
-
```yml
|
13
|
-
picture:
|
14
|
-
source: "assets/images/fullsize"
|
15
|
-
output: "assets/images/generated"
|
16
|
-
```
|
17
|
-
|
18
|
-
* **Source Image Directory**
|
19
|
-
|
20
|
-
*Format:* `source: (directory)`
|
21
|
-
|
22
|
-
*Example:* `source: images/`
|
23
|
-
|
24
|
-
*Default:* Jekyll site root.
|
25
|
-
|
26
|
-
To make writing tags easier you can specify a source directory for your assets. Base images in the
|
27
|
-
tag will be relative to the `source` directory, which is relative to the Jekyll site root.
|
28
|
-
|
29
|
-
{% raw %}
|
30
|
-
For example, if `source` is set to `assets/images/_fullsize`, the tag
|
31
|
-
`{% picture enishte/portrait.jpg --alt An unsual picture %}` will look for a file at
|
32
|
-
{% endraw %}
|
33
|
-
`assets/images/_fullsize/enishte/portrait.jpg`.
|
34
|
-
|
35
|
-
* **Destination Image Directory**
|
36
|
-
|
37
|
-
*Format:* `output: (directory)`
|
38
|
-
|
39
|
-
*Example:* `output: resized_images/`
|
40
|
-
|
41
|
-
*Default*: `generated/`
|
42
|
-
|
43
|
-
Jekyll Picture Tag saves resized, reformatted images to the `output` directory in your compiled
|
44
|
-
site. The organization of your `source` directory is maintained.
|
45
|
-
|
46
|
-
This setting is relative to your compiled site, which means `_site` unless you've changed it.
|
47
|
-
|
48
|
-
* **Suppress Warnings**
|
49
|
-
|
50
|
-
*Format:* `suppress_warnings: (true|false)`
|
51
|
-
|
52
|
-
*Example:* `suppress_warnings: true`
|
53
|
-
|
54
|
-
*Default*: `false`
|
55
|
-
|
56
|
-
Jekyll Picture Tag will warn you in a few different scenarios, such as when your base image is
|
57
|
-
smaller than one of the sizes in your preset. (Note that Jekyll Picture Tag will never resize an
|
58
|
-
image to be larger than its source). Set this value to `true`, and these warnings will not be shown.
|
59
|
-
|
60
|
-
* **Continue build with missing source images**
|
61
|
-
|
62
|
-
*Format:* `ignore_missing_images: (boolean|environment name|array of environments)`
|
63
|
-
|
64
|
-
*Example:* `ignore_missing_images: [development, testing]`
|
65
|
-
|
66
|
-
*Default:* `false`
|
67
|
-
|
68
|
-
Normally, JPT will raise an error if a source image is missing, causing the entire site build to
|
69
|
-
fail. This setting allows you to bypass this behavior and continue the build, either for certain
|
70
|
-
build environments or all the time. I highly encourage you to set this to `development`, and set
|
71
|
-
the jekyll build environment to `production` when you build for production so you don't shoot
|
72
|
-
yourself in the foot (publish a site with broken images). You can read more about Jekyll
|
73
|
-
environments [here](https://jekyllrb.com/docs/configuration/environments/).
|
74
|
-
|
75
|
-
* **Use Relative Urls**
|
76
|
-
|
77
|
-
*Format:* `relative_url: (true|false)`
|
78
|
-
|
79
|
-
*Example:* `relative_url: false`
|
80
|
-
|
81
|
-
*Default*: `true`
|
82
|
-
|
83
|
-
Whether to use relative (`/generated/test(...).jpg`) or absolute
|
84
|
-
(`https://example.com/generated/test(...).jpg`) urls in your src and srcset attributes.
|
85
|
-
|
86
|
-
* **Use a CDN Url**
|
87
|
-
|
88
|
-
*Format:* `cdn_url: (url)`
|
89
|
-
|
90
|
-
*Example:* `cdn_url: https://cdn.example.com`
|
91
|
-
|
92
|
-
*Default*: none
|
93
|
-
|
94
|
-
Use for images that are hosted at a different domain or subdomain than the Jekyll site root. Overrides
|
95
|
-
`relative_url`. Keep reading, the next option is important.
|
96
|
-
|
97
|
-
* **CDN build environments**
|
98
|
-
|
99
|
-
*Format:* `cdn_environments: (array of strings)`
|
100
|
-
|
101
|
-
*Example:* `cdn_environments: ['production', 'staging']`
|
102
|
-
|
103
|
-
*Default*: `['production']`
|
104
|
-
|
105
|
-
It's likely that if you're using a CDN, you may not want to use it in your local development environment. This
|
106
|
-
allows you to build a site with local images while in development, and still push to a CDN when you build for
|
107
|
-
production by specifying a different [environment](https://jekyllrb.com/docs/configuration/environments/).
|
108
|
-
|
109
|
-
**Note that the default jekyll environment is `development`**, meaning that if you only set `cdn_url` and run
|
110
|
-
`jekyll serve` or `jekyll build`, nothing will change. You'll either need to run `JEKYLL_ENV=production bundle exec
|
111
|
-
jekyll build`, or add `development` to this setting.
|
112
|
-
|
113
|
-
* **Kramdown nomarkdown fix**
|
114
|
-
|
115
|
-
*Format:* `nomarkdown: (true|false)`
|
116
|
-
|
117
|
-
*Example:* `nomarkdown: false`
|
118
|
-
|
119
|
-
*Default:* `true`
|
120
|
-
|
121
|
-
Whether or not to surround j-p-t's output with a `{::nomarkdown}..{:/nomarkdown}` block when called
|
122
|
-
from within a markdown file.
|
123
|
-
|
124
|
-
This setting is overridden by the same setting in a preset. See [the notes]({{ site.baseurl
|
125
|
-
}}/notes) for more detailed information.
|
126
|
-
|
127
|
-
* **Fast Build**
|
128
|
-
|
129
|
-
*Format:* `fast_build: (true|false|environment|array of environments)`
|
130
|
-
|
131
|
-
*Examples:*
|
132
|
-
|
133
|
-
- `fast_build: true`
|
134
|
-
|
135
|
-
- `fast_build: development`
|
136
|
-
|
137
|
-
- `fast_build: [development, staging]`
|
138
|
-
|
139
|
-
*Default:* `false`
|
140
|
-
|
141
|
-
Makes a tradeoff: Speeds repeated build times for sites with many images, by assuming that the
|
142
|
-
filename alone is enough to uniquely identify a source image. This doesn't speed up image
|
143
|
-
generation, just detection of whether or not it's necessary.
|
144
|
-
|
145
|
-
Ordinarily, JPT generates an MD5 hash for every source image, every site build. This ensures that
|
146
|
-
if you replace one image with another, but keep the filename the same, JPT will correctly generate
|
147
|
-
images for the new file. If you have many large images and/or limited hardware, this can take some
|
148
|
-
time and make the development process painful. Enable this setting to skip MD5 hash checking on
|
149
|
-
existing generated images (most of the time), and just assume that if the filename, format, and
|
150
|
-
width match then it's the right one. If there are multiple possible matches (resulting from
|
151
|
-
leftover generated images from previous filename replacements), it'll compute a hash instead of
|
152
|
-
guessing randomly.
|
153
|
-
|
154
|
-
* **Disable Jekyll Picture Tag**
|
155
|
-
|
156
|
-
*Format:* `disabled: (true|false|environment|array of environments)`
|
157
|
-
|
158
|
-
*Examples:*
|
159
|
-
|
160
|
-
- `disabled: true`
|
161
|
-
|
162
|
-
- `disabled: development`
|
163
|
-
|
164
|
-
- `disabled: [development, staging]`
|
165
|
-
|
166
|
-
*Default:* `false`
|
167
|
-
|
168
|
-
Disable image and markup generation entirely. Useful for debugging, or to speed up site builds
|
169
|
-
when you're working on something else.
|
170
|
-
|
171
|
-
Hint: If you're going to toggle this on and off frequently, you might just use an environment
|
172
|
-
variable. Set this to something like `nopics`, and then start the Jekyll server with something
|
173
|
-
like `JEKYLL_ENV=nopics bundle exec jekyll serve` when you don't want image generation.
|
data/docs/installation.md
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
---
|
2
|
-
---
|
3
|
-
|
4
|
-
# Installation
|
5
|
-
|
6
|
-
- Add `jekyll_picture_tag` to your Gemfile in the `:jekyll_plugins` group:
|
7
|
-
|
8
|
-
```ruby
|
9
|
-
group :jekyll_plugins do
|
10
|
-
gem 'jekyll_picture_tag'
|
11
|
-
end
|
12
|
-
```
|
13
|
-
|
14
|
-
- Run `$ bundle install`
|
15
|
-
|
16
|
-
- See if you have ImageMagick with `$ convert --version`. You should see something like this:
|
17
|
-
|
18
|
-
```
|
19
|
-
~ $ convert --version
|
20
|
-
Version: ImageMagick 7.0.8-14 Q16 x86_64 2018-10-31 https://imagemagick.org
|
21
|
-
Copyright: © 1999-2018 ImageMagick Studio LLC License: https://imagemagick.org/script/license.php
|
22
|
-
Features: Cipher DPC HDRI OpenMP Delegates (built-in): bzlib fontconfig freetype jng jp2 jpeg lcms
|
23
|
-
lzma pangocairo png tiff webp xml zlib
|
24
|
-
```
|
25
|
-
|
26
|
-
If you get a 'command not found' error, you'll need to install it. Most package managers know about
|
27
|
-
ImageMagick, otherwise it can be found [here](https://imagemagick.org/script/download.php).
|
28
|
-
|
29
|
-
- **Note webp under delegates.** This is required if you want to generate webp files. Any image format
|
30
|
-
you want to handle will require an appropriate delegate; You may have to install additional packages
|
31
|
-
to accomplish this.
|
32
|
-
|
33
|
-
## Cropping and Imagemagick
|
34
|
-
|
35
|
-
Cropping to an aspect ratio depends on ImageMagick 7+. Ubuntu, somewhat annoyingly, only offers
|
36
|
-
version 6 in its official repositories. This matters even if you don't run Ubuntu, because many
|
37
|
-
build & deployment services you might use (including Netlify and Travis CI) do.
|
38
|
-
|
39
|
-
If you'd like to use both the cropping feature and such a service, or it's inconvenient to install
|
40
|
-
version 7 in your development environment, you will likely want to build your site in a docker
|
41
|
-
container. The Alpine Linux repos include version 7, so you'll want an Alpine Linux based image
|
42
|
-
rather than an Ubuntu based one. Conveniently this includes the [offical Jekyll
|
43
|
-
image](https://hub.docker.com/r/jekyll/jekyll).
|
44
|
-
|
45
|
-
Once I work out how to actually do that, I'll add some guidance here.
|
data/docs/notes.md
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
---
|
2
|
-
---
|
3
|
-
# Notes and FAQ
|
4
|
-
|
5
|
-
* #### Github Pages?
|
6
|
-
|
7
|
-
Github Pages only allows a very short whitelist of plugins, which sadly does not include JPT. You
|
8
|
-
can either run it locally, then commit and push the generated files (rather than the source
|
9
|
-
files), or just host it some other way. I recommend Netlify.
|
10
|
-
|
11
|
-
* #### HTML attributes
|
12
|
-
|
13
|
-
Jekyll Picture Tag has comprehensive attribute support for all generated HTML. You can add
|
14
|
-
attributes both through the [liquid tag]({{ site.baseurl }}/usage), and the [preset]({{
|
15
|
-
site.baseurl }}/presets) (scroll down a bit).
|
16
|
-
|
17
|
-
* ### Input checking
|
18
|
-
|
19
|
-
Jekyll Picture Tag is very trusting. It doesn't do much checking of your inputs, and it does not
|
20
|
-
fail gracefully if you for example pass it a string when it expects an array. It's on the to-do
|
21
|
-
list, but for now if you get cryptic errors then double-check your settings and tag arguments.
|
22
|
-
|
23
|
-
* ### Git LFS
|
24
|
-
|
25
|
-
I'm Putting this here because it bit me: If you want to use git LFS, make sure that your hosting
|
26
|
-
provider makes those images available during the build process. Netlify, for example, does not.
|
27
|
-
You won't find this out until you have gone through the entire migration process and try to deploy
|
28
|
-
for the first time.
|
29
|
-
|
30
|
-
|
31
|
-
* #### Extra {::nomarkdown} tags or mangled HTML?
|
32
|
-
|
33
|
-
**TLDR up front:** There's a bug involving `<picture>` tags wrapped in `<a>` tags which is not in my
|
34
|
-
power to fix.
|
35
|
-
|
36
|
-
* If you're getting extra `{::nomarkdown}` tags floating around your images, add `nomarkdown:
|
37
|
-
false` to either the relevant preset or under `picture` in `_config.yml`.
|
38
|
-
|
39
|
-
* If you're getting mangled HTML when trying to wrap images with anchor tags, add `nomarkdown:
|
40
|
-
true` to the preset.
|
41
|
-
|
42
|
-
**What's going on here:**
|
43
|
-
|
44
|
-
Kramdown is Jekyll's default markdown parser. Kramdown gets grumpy when you give it a block level
|
45
|
-
element (such as a `<picture>`) surrounded by a span level element (such as an `<a>`), and horribly
|
46
|
-
mangles it. The fix for this is to tell Kramdown to chill with a `{::nomarkdown}..{:/nomarkdown}`
|
47
|
-
wrapper.
|
48
|
-
|
49
|
-
Jekyll Picture Tag can be called from many different places: a markdown file, an HTML file, an HTML
|
50
|
-
layout for a markdown file, and an HTML include, to name a few. JPT tries its best to determine
|
51
|
-
whether its output will be parsed by Kramdown or not, but Jekyll itself doesn't make this
|
52
|
-
particularly easy which results in some false positives. (The one I'm most aware of is when a
|
53
|
-
markdown file uses an HTML layout which includes a picture tag.)
|
54
|
-
|
55
|
-
Unfortunately, I don't see an easy way to fix this. We've gotten this far mostly by trial and error.
|
56
|
-
I'll continue to work on improving the autodetection, but you can override this behavior explicitly.
|
57
|
-
|
58
|
-
**The fix:**
|
59
|
-
|
60
|
-
By default, JPT will add a `{::nomarkdown}` tag if all of the following are true:
|
61
|
-
* It thinks it's called from a markdown page
|
62
|
-
* The image will be wrapped in an anchor tag (i.e. `link_source_image:` or a `--link` parameter)
|
63
|
-
* This behavior hasn't been explicitly disabled.
|
64
|
-
|
65
|
-
You can disable nomarkdown tags globally by setting `nomarkdown: false` under the `picture:` key in
|
66
|
-
`_config.yml`.
|
67
|
-
|
68
|
-
You can enable or disable markdown tags per preset by adding `nomarkdown: true|false` to them.
|
69
|
-
**This setting overrides everything else, both JPT autodetection and the global setting.**
|
70
|
-
|
71
|
-
* ### Managing Generated Images
|
72
|
-
|
73
|
-
Jekyll Picture Tag creates resized versions of your images when you build the site. It uses a
|
74
|
-
smart caching system to speed up site compilation, and re-uses images as much as possible.
|
75
|
-
Filenames take the following format:
|
76
|
-
|
77
|
-
`(original name without extension)-(width)-(source hash).(filetype)`
|
78
|
-
|
79
|
-
Source hash is the first 5 characters of an md5 checksum of the source image.
|
80
|
-
|
81
|
-
Try to use a base image that is larger than the largest resized image you need. Jekyll Picture Tag
|
82
|
-
will warn you if a base image is too small, and won't upscale images.
|
83
|
-
|
84
|
-
By specifying a `source` directory that is ignored by Jekyll you can prevent huge base images from
|
85
|
-
being copied to the compiled site. For example, `source: assets/images/_fullsize` and `output:
|
86
|
-
generated` will result in a compiled site that contains resized images but not the originals. Note
|
87
|
-
that this will break source image linking, if you wish to enable it. (Can't link to images that
|
88
|
-
aren't public!)
|
89
|
-
|
90
|
-
The `output` directory is never deleted by Jekyll. You may want to empty it once in awhile, to
|
91
|
-
clear out unused images.
|
data/docs/output.md
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
---
|
2
|
-
---
|
3
|
-
|
4
|
-
# Output Formats
|
5
|
-
|
6
|
-
This is a listing of the various text arrangements that JPT can give you. Select one by setting
|
7
|
-
`markup:` in the relevant [markup preset]({{ site.baseurl }}/presets).
|
8
|
-
|
9
|
-
Example:
|
10
|
-
|
11
|
-
```yml
|
12
|
-
# /_data/picture.yml
|
13
|
-
|
14
|
-
markup_presets:
|
15
|
-
my_preset:
|
16
|
-
markup: data_auto
|
17
|
-
```
|
18
|
-
|
19
|
-
## Standard HTML:
|
20
|
-
|
21
|
-
- **`picture`:** `<picture>` element surrounding a `<source>` tag for each required srcset, and a
|
22
|
-
fallback `<img>`.
|
23
|
-
|
24
|
-
- **`img`:** output a single `<img>` tag with a `srcset` entry.
|
25
|
-
|
26
|
-
- **`auto`:** Supply an img tag when you have only one srcset, otherwise supply a picture tag.
|
27
|
-
|
28
|
-
## Javascript Friendly:
|
29
|
-
|
30
|
-
- **`data_picture`, `data_img`, `data_auto`:** Analogous to their counterparts above, but instead of
|
31
|
-
`src`, `srcset`, and `sizes`, you get `data-src`, `data-srcset`, and `data-sizes`. This allows you
|
32
|
-
to use javascript for things like [lazy loading](https://github.com/verlok/lazyload).
|
33
|
-
|
34
|
-
#### Special Options
|
35
|
-
|
36
|
-
The following preset configuration settings only apply to the `data_` output formats.
|
37
|
-
|
38
|
-
- **noscript**
|
39
|
-
|
40
|
-
_Format:_ `noscript: true|false`
|
41
|
-
|
42
|
-
_Default:_ `false`
|
43
|
-
|
44
|
-
Include a basic `img` fallback within a `<noscript>` tag, giving your javascript-disabled users
|
45
|
-
something to look at.
|
46
|
-
|
47
|
-
- **data_sizes**
|
48
|
-
|
49
|
-
_Format:_ `data_sizes: true|false`
|
50
|
-
|
51
|
-
_Default:_ `true`
|
52
|
-
|
53
|
-
This option sets whether you would like JPT's auto-generated sizes to be returned as a
|
54
|
-
`data-sizes` attribute or a normal `sizes` attribute. (Useful for interfacing nicely with all the
|
55
|
-
various JS image libraries out there.)
|
56
|
-
|
57
|
-
## Fragments:
|
58
|
-
|
59
|
-
- **`direct_url`**: Generates an image and returns only its url. Uses `fallback_` properties (width
|
60
|
-
and format).
|
61
|
-
|
62
|
-
- **`naked_srcset`**: Builds a srcset and nothing else (not even the surrounding quotes). Note that the
|
63
|
-
(image) `format` setting must still be an array, even if you only give it one value.
|
data/docs/presets.md
DELETED
@@ -1,391 +0,0 @@
|
|
1
|
-
---
|
2
|
-
---
|
3
|
-
|
4
|
-
# Writing Presets
|
5
|
-
|
6
|
-
Presets are named collections of settings that determine basically everything about JPT's output.
|
7
|
-
They are stored in `_data/picture.yml`, to avoid cluttering `_config.yml`. You will have to create
|
8
|
-
this file, and probably the `_data/` directory as well.
|
9
|
-
|
10
|
-
Here's an [example data file]({{ site.baseurl }}/example_presets).
|
11
|
-
|
12
|
-
Any settings which are specific to particular output formats are documented on the [output
|
13
|
-
formats]({{site.baseurl}}/output) page.
|
14
|
-
|
15
|
-
## Required Knowledge
|
16
|
-
|
17
|
-
If you don't know the difference between resolution switching and art direction, stop now and read
|
18
|
-
the [MDN Responsive Images
|
19
|
-
guide](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images)
|
20
|
-
in detail. Ideally, play around with a basic HTML file, a few test images, and a few different
|
21
|
-
browser widths until you understand it.
|
22
|
-
|
23
|
-
## Media Presets
|
24
|
-
|
25
|
-
_Format:_
|
26
|
-
|
27
|
-
```yml
|
28
|
-
media_presets:
|
29
|
-
(name): (css media query)
|
30
|
-
(name): (css media query)
|
31
|
-
(...)
|
32
|
-
|
33
|
-
```
|
34
|
-
|
35
|
-
_Example:_
|
36
|
-
|
37
|
-
```yml
|
38
|
-
media_presets:
|
39
|
-
desktop: "min-width: 1200px"
|
40
|
-
```
|
41
|
-
|
42
|
-
These are named media queries for use in a few different places: specifying alternate source images
|
43
|
-
in your liquid tag, building the 'sizes' attribute within your presets, and in a few configuration
|
44
|
-
settings. Quotes are recommended around the media queries, because yml gets confused by colons.
|
45
|
-
|
46
|
-
## Markup Presets
|
47
|
-
|
48
|
-
_Format:_
|
49
|
-
|
50
|
-
```yml
|
51
|
-
markup_presets:
|
52
|
-
(name):
|
53
|
-
(option): (setting)
|
54
|
-
(option): (setting)
|
55
|
-
(...)
|
56
|
-
(...)
|
57
|
-
```
|
58
|
-
|
59
|
-
_Example:_
|
60
|
-
|
61
|
-
```yml
|
62
|
-
markup_presets:
|
63
|
-
default:
|
64
|
-
formats: [webp, original]
|
65
|
-
widths: [200, 400, 800, 1600]
|
66
|
-
link_source: true
|
67
|
-
lazy:
|
68
|
-
markup: data_auto
|
69
|
-
widths: [200, 400, 800, 1600]
|
70
|
-
link_source: true
|
71
|
-
noscript: true
|
72
|
-
```
|
73
|
-
|
74
|
-
Each entry is a pre-defined collection of settings to build a given chunk of text (usually HTML) and
|
75
|
-
its respective images. You can select one as the first argument given to the tag:
|
76
|
-
|
77
|
-
{% raw %}
|
78
|
-
`{% picture my-preset image.jpg %}`
|
79
|
-
{% endraw %}
|
80
|
-
|
81
|
-
The `default` preset will be used if none is specified. A preset name can't contain a `.` (period).
|
82
|
-
|
83
|
-
#### A Note on srcsets
|
84
|
-
|
85
|
-
For images that are different sizes on different screens (most images), use a width-based srcset
|
86
|
-
(which is the default). Specify a `widths` setting (or don't, for the default set), and optionally
|
87
|
-
the `sizes` and `size` settings.
|
88
|
-
|
89
|
-
Use a multiplier-based srcset when the image will always be the same size, regardless of screen
|
90
|
-
width (thumbnails and icons). To use a multiplier-based srcset, set `pixel_ratios` and `base_width`.
|
91
|
-
|
92
|
-
### Settings reference
|
93
|
-
|
94
|
-
- **Markup format**
|
95
|
-
|
96
|
-
_Format:_ `markup: (setting)`
|
97
|
-
|
98
|
-
_Default_: `auto`
|
99
|
-
|
100
|
-
Defines what format the generated text will take. They are documented [here]({{ site.baseurl }}/output).
|
101
|
-
|
102
|
-
* **Image Formats**
|
103
|
-
|
104
|
-
_Format:_ `format: [format1, format2, (...)]`
|
105
|
-
|
106
|
-
_Example:_ `format: [webp, original]`
|
107
|
-
|
108
|
-
_Default_: `original`
|
109
|
-
|
110
|
-
Array (yml sequence) of the image formats you'd like to generate, in decreasing order of
|
111
|
-
preference. Browsers will render the first format they find and understand, so **If you put jpg
|
112
|
-
before webp, your webp images will never be used**. `original` does what you'd expect. To supply
|
113
|
-
webp, you must have an imagemagick webp delegate installed. (Most package managers just name it
|
114
|
-
'webp')
|
115
|
-
|
116
|
-
_Supported formats are anything which imagemagick supports, and has an installed delegate. See a
|
117
|
-
list by running `$ convert --version`_
|
118
|
-
|
119
|
-
* **Widths**
|
120
|
-
|
121
|
-
_Format:_ `widths: [integer, integer, (...)]`
|
122
|
-
|
123
|
-
_Example:_ `widths: [600, 800, 1200]`
|
124
|
-
|
125
|
-
_Default_: `[400, 600, 800, 1000]`
|
126
|
-
|
127
|
-
Array of image widths to generate, in pixels. For use when you want a width-based srcset
|
128
|
-
(`srcset="img.jpg 800w, img2.jpg 1600w"`).
|
129
|
-
|
130
|
-
* **Media_widths**
|
131
|
-
|
132
|
-
_Format:_
|
133
|
-
|
134
|
-
```yml
|
135
|
-
media_widths:
|
136
|
-
(media preset name): [integer, integer, (...)]
|
137
|
-
```
|
138
|
-
|
139
|
-
_Example:_
|
140
|
-
|
141
|
-
```yml
|
142
|
-
media_widths:
|
143
|
-
mobile: [400, 600, 800]
|
144
|
-
```
|
145
|
-
|
146
|
-
_Default:_ Widths setting
|
147
|
-
|
148
|
-
If you are using art direction, there is no sense in generating desktop-size files for your mobile
|
149
|
-
image. You can specify sets of widths to associate with given media queries. If not specified,
|
150
|
-
will use `widths` setting.
|
151
|
-
|
152
|
-
* **Sizes**
|
153
|
-
|
154
|
-
_Format:_
|
155
|
-
|
156
|
-
```yml
|
157
|
-
sizes:
|
158
|
-
(media preset): (CSS dimension)
|
159
|
-
(...)
|
160
|
-
```
|
161
|
-
|
162
|
-
_Example:_
|
163
|
-
|
164
|
-
```yml
|
165
|
-
sizes:
|
166
|
-
mobile: 80vw
|
167
|
-
tablet: 60vw
|
168
|
-
desktop: 900px
|
169
|
-
```
|
170
|
-
|
171
|
-
Conditional sizes, used to construct the `sizes=` HTML attribute telling the browser how wide your
|
172
|
-
image will be (on the screen) when a given media query is true. CSS dimensions can be given in
|
173
|
-
`px`, `em`, or `vw`. To be used along with a width-based srcset.
|
174
|
-
|
175
|
-
Provide these in order of most restrictive to least restrictive. The browser will choose the
|
176
|
-
first one with an applicable media query.
|
177
|
-
|
178
|
-
You don't have to provide a sizes attribute at all. If you don't, the browser will assume the
|
179
|
-
image is 100% the width of the viewport.
|
180
|
-
|
181
|
-
* **Size**
|
182
|
-
|
183
|
-
_Format:_ `size: (CSS Dimension)`
|
184
|
-
|
185
|
-
_Example:_ `size: 80vw`
|
186
|
-
|
187
|
-
Unconditional `sizes` setting, to be supplied either alone or after all conditional sizes.
|
188
|
-
|
189
|
-
* **Pixel Ratios**
|
190
|
-
|
191
|
-
_Format:_ `pixel_ratios: [number, number, number (...)]`
|
192
|
-
|
193
|
-
_Example:_ `pixel_ratios: [1, 1.5, 2]`
|
194
|
-
|
195
|
-
Array of images to construct, given in multiples of the base width. If you set this, you must also
|
196
|
-
give a `base_width`.
|
197
|
-
|
198
|
-
Set this when you want a multiplier based srcset (example: `srcset="img.jpg 1x, img2.jpg 2x"`).
|
199
|
-
|
200
|
-
* **Base Width**
|
201
|
-
|
202
|
-
_Format:_ `base_width: integer`
|
203
|
-
|
204
|
-
_Example:_ `base_width: 100`
|
205
|
-
|
206
|
-
When using pixel ratios, you must supply a base width. This sets how wide the 1x image should be.
|
207
|
-
|
208
|
-
* **Crop & Media Crop**
|
209
|
-
|
210
|
-
_Format:_
|
211
|
-
|
212
|
-
```yml
|
213
|
-
crop: (geometery)
|
214
|
-
media_crop:
|
215
|
-
(media_preset): (geometry)
|
216
|
-
(media_preset): (geometry)
|
217
|
-
(...)
|
218
|
-
```
|
219
|
-
|
220
|
-
_Example:_
|
221
|
-
|
222
|
-
```yml
|
223
|
-
crop: 16:9
|
224
|
-
media_crop:
|
225
|
-
tablet: 3:2
|
226
|
-
mobile: 1:1
|
227
|
-
```
|
228
|
-
|
229
|
-
**Check the [ installation guide ](installation) before using this feature.**
|
230
|
-
|
231
|
-
Crop geometry, given either generally or for specific media presets. The hierarchy is:
|
232
|
-
`tag argument` > `media_crop:` > `crop:`.
|
233
|
-
|
234
|
-
This setting accepts the same arguments as the `crop geometry` [tag parameter](usage).
|
235
|
-
|
236
|
-
|
237
|
-
* **Gravity & Media_gravity**
|
238
|
-
|
239
|
-
```yml
|
240
|
-
crop: (gravity)
|
241
|
-
media_crop:
|
242
|
-
(media_preset): (gravity)
|
243
|
-
(media_preset): (gravity)
|
244
|
-
(...)
|
245
|
-
```
|
246
|
-
|
247
|
-
_Example:_
|
248
|
-
|
249
|
-
```yml
|
250
|
-
crop: north
|
251
|
-
media_crop:
|
252
|
-
tablet: east
|
253
|
-
mobile: southwest
|
254
|
-
```
|
255
|
-
|
256
|
-
Crop gravity, given either generally or for specific media presets. The hierarchy is:
|
257
|
-
`tag argument` > `media_crop:` > `crop:` > `center` (default).
|
258
|
-
|
259
|
-
This setting accepts the same arguments as the `crop gravity` [tag parameter](usage).
|
260
|
-
|
261
|
-
* **Quality**
|
262
|
-
|
263
|
-
_Format:_ `quality: 0 <= integer <= 100`
|
264
|
-
|
265
|
-
_Example:_ `quality: 80`
|
266
|
-
|
267
|
-
_Default:_ `75`
|
268
|
-
|
269
|
-
This allows you to specify an image compression level for all image formats (where it makes sense,
|
270
|
-
anyway). The next option allows you to set them per format.
|
271
|
-
|
272
|
-
* **Format Quality**
|
273
|
-
|
274
|
-
_Format:_
|
275
|
-
|
276
|
-
```yml
|
277
|
-
format_quality:
|
278
|
-
(format): 0 <= integer <= 100
|
279
|
-
(...)
|
280
|
-
```
|
281
|
-
|
282
|
-
_Example:_
|
283
|
-
|
284
|
-
```
|
285
|
-
format_quality:
|
286
|
-
jpg: 75
|
287
|
-
png: 65
|
288
|
-
webp: 55
|
289
|
-
```
|
290
|
-
|
291
|
-
_Default:_ quality setting (above)
|
292
|
-
|
293
|
-
This allows you to specify quality settings for various image formats, allowing you to take
|
294
|
-
advantage of webp's better compression algorithm without trashing your jpg images (for example).
|
295
|
-
If you don't give a setting for a particular format it'll fall back to the `quality` setting
|
296
|
-
above, and if you don't set _that_ it'll default to 75.
|
297
|
-
|
298
|
-
* **Width & Height attributes (Anti-Loading-Jank)**
|
299
|
-
|
300
|
-
_Format:_
|
301
|
-
|
302
|
-
```yml
|
303
|
-
dimension_attributes: true | false
|
304
|
-
```
|
305
|
-
|
306
|
-
_Example:_
|
307
|
-
|
308
|
-
```yml
|
309
|
-
dimension_attributes: true
|
310
|
-
```
|
311
|
-
|
312
|
-
_Default:_ `false`
|
313
|
-
|
314
|
-
Prevent page reflow (aka jank) while images are loading, by adding `width` and `height` attributes
|
315
|
-
to the `<img>` tag in the correct aspect ratio.
|
316
|
-
|
317
|
-
For an explanation of why and how you want to do this, [here](https://youtu.be/4-d_SoCHeWE) is a
|
318
|
-
great explanation.
|
319
|
-
|
320
|
-
Caveats:
|
321
|
-
* You need `width: 100%;` and `height: auto;` (or vice versa) set in CSS on the `<img>`
|
322
|
-
tags, or they will be stretched weirdly.
|
323
|
-
* This works on `<img>` tags and `<picture>` tags when offering images in multiple widths and
|
324
|
-
formats, but it does not work if you are using art direction (in other words, if you have
|
325
|
-
multiple source images). This is because these attributes can only be applied to the `<img>`
|
326
|
-
tag, of which there is exactly one.
|
327
|
-
|
328
|
-
* **Arbitrary HTML Attributes**
|
329
|
-
|
330
|
-
_Format:_
|
331
|
-
|
332
|
-
```yml
|
333
|
-
attributes:
|
334
|
-
(element): '(attributes)'
|
335
|
-
(...)
|
336
|
-
```
|
337
|
-
|
338
|
-
_Example:_
|
339
|
-
|
340
|
-
```yml
|
341
|
-
attributes:
|
342
|
-
img: 'class="soopercool" data-awesomeness="11"'
|
343
|
-
picture: 'class="even-cooler"'
|
344
|
-
```
|
345
|
-
|
346
|
-
HTML attributes you would like to add. The same arguments are available here as in the liquid
|
347
|
-
tag: HTML element names, `alt:`, `link:`, and `parent:`. Unescaped double quotes cause problems
|
348
|
-
with yml, so it's recommended to surround them with single quotes.
|
349
|
-
|
350
|
-
* **Fallback Width**
|
351
|
-
|
352
|
-
_Format:_ `fallback_width: (integer)`
|
353
|
-
|
354
|
-
_Example:_ `fallback_width: 800`
|
355
|
-
|
356
|
-
_Default_: `800`
|
357
|
-
|
358
|
-
Width of the fallback image.
|
359
|
-
|
360
|
-
* **Fallback Format**
|
361
|
-
|
362
|
-
_Format:_ `fallback_format: (format)`
|
363
|
-
|
364
|
-
_Example:_ `fallback_format: jpg`
|
365
|
-
|
366
|
-
_Default_: `original`
|
367
|
-
|
368
|
-
Format of the fallback image
|
369
|
-
|
370
|
-
* **Source Image Link**
|
371
|
-
|
372
|
-
_Format:_ `link_source: (true|false)`
|
373
|
-
|
374
|
-
_Example:_ `link_source: true`
|
375
|
-
|
376
|
-
_Default:_ `false`
|
377
|
-
|
378
|
-
Surround image with a link to the original source file. Your source image directory must be
|
379
|
-
published as part of the compiled site. If you run into weird issues with the output, see
|
380
|
-
the [notes]({{ site.baseurl }}/notes).
|
381
|
-
|
382
|
-
* **Nomarkdown override**
|
383
|
-
|
384
|
-
_Format:_ `nomarkdown: (true|false)`
|
385
|
-
|
386
|
-
_Example:_ `nomarkdown: false`
|
387
|
-
|
388
|
-
_Default:_ `nil`
|
389
|
-
|
390
|
-
Hard setting for `{::nomarkdown}` tags, overrides both autodetection and the global setting in
|
391
|
-
`_config.yml`. See the [notes]({{ site.baseurl }}/notes) for a detailed explanation.
|