Skip to content

Commit fd05c85

Browse files
committed
Add crop and quality attributes to image tag
Also, omit some of the unused global attributes.
1 parent 78c947e commit fd05c85

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

tags/image.md

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ The tag is also context-sensitive: if an `id` or `name` attribute is not specifi
3131

3232
Tag will accept the following attributes (**case-sensitive**) as well as the {% include atts-global-link.html %}:
3333

34+
`crop="crop value"` <span class="footnote warning">v4.9.0+</span>
35+
: When using automatic thumbnails, specifies a cropping ratio and optional cropper.
36+
: **Values:** A width-to-height ratio, specified as two numbers separated by either `x`, `:` or `.` (e.g. `4x3`, `16:9`, `1.1`).
37+
: A third parameter can be added after another `x`, `:` or `.` to specify which cropper to use:
38+
`centered` (the default). Crop the edges on all four sides. Fast.
39+
`topcentered`. Crop the bottom, left and right edges only. Fast.
40+
`smart`. Automatically crop based on analysis of the image to try and keep the subject as the focus. Slowest, and results may vary depending on the image.
41+
For example: `crop="2:3.smart"` applies a smart cropper in the portrait 2-to-3 ratio.
42+
: **Default:** unset (thumbnails will be scaled only).
43+
3444
`escape="html"` <span class="footnote warning">v4.0.4+</span>
3545
: Escape [HTML entities](https://developer.mozilla.org/en-US/docs/Glossary/Entity) such as `<`, `>` and `&` for the image's `alt` and `title` attributes.
3646
: **Values:** See the [tag escaping](/tags/learning/#tag-escaping) documentation for all possible values.
@@ -40,10 +50,6 @@ Tag will accept the following attributes (**case-sensitive**) as well as the {%
4050
: Specify an image `height` which overrides the value stored in the database. Use `height="0"` to turn off the output of a width attribute in the `<img>` tag (thus the browser will scale the height if a width is used).
4151
: **Default:** height of image stored in the database.
4252

43-
`html_id="id"` <span class="footnote warning">v4.0.4+</span>
44-
: The HTML `id` attribute applied to the `wraptag`, if set, otherwise to the `<img>` tag.
45-
: **Default:** unset.
46-
4753
`id="integer"`
4854
: Specifies the `id`, assigned at upload of the image, to display. Can be found on the Images panel. If both `name` and `id` are specified, `name` is used while `id` is ignored. If neither is specified, the tag must be used within an [images](/tags/images) tag or form.
4955

@@ -55,13 +61,17 @@ Tag will accept the following attributes (**case-sensitive**) as well as the {%
5561
`name="image name"`
5662
: Specifies which image to display by its image `name` as shown on the Images panel.
5763

64+
`quality="percentage"`
65+
: The thumbnail quality percentage value from 1 to 100. In general, the higher the number, the better quality the image, the larger the image size.
66+
: Only applicable to PNG, JPG, WEBP, and AVIF files. Has no effect on other file formats.
67+
5868
`style="style rule"`
5969
: Inline CSS `style` rule. It's recommended that you assign CSS rules via the `class` attribute instead.
6070
: **Default:** unset.
6171

62-
`thumbnail="boolean"` <span class="footnote warning">v4.8.0+</span>
63-
: Whether to display the full-size (0) or thumbnail-size (1) image.
64-
: **Default:** 0.
72+
`thumbnail="number"` <span class="footnote warning">v4.8.0+</span>
73+
: Whether to display the full-size (0), custom thumbnail-size (1), or an automatically-sized (2) image.
74+
: **Default:** The thumbnail flavour chosen for this image during upload.
6575

6676
`title="boolean|title text"` <span class="footnote warning">v4.8.0+</span>
6777
: Adds the given text as an HTML 'title' attribute to the image. If used as a valueless attribute, will use the caption as text.
@@ -70,7 +80,7 @@ Tag will accept the following attributes (**case-sensitive**) as well as the {%
7080
: Specify an image `width` which overrides the value stored in the database. Use `width="0"` to turn off the output of a width attribute in the `<img>` tag (thus the browser will scale the width if a height is used).
7181
: **Default:** width of image stored in the database.
7282

73-
{% include atts-global.html %}
83+
{% include atts-global.html sort="" limit="" offset="" %}
7484

7585
## Examples
7686

@@ -102,8 +112,23 @@ Had the `wraptag` attribute been used, the `class="promoted"` attribute/value wo
102112

103113
Displays full-size images for all images found by the [images](/tags/images) tag.
104114

115+
### Example 4: Display an automatic thumbnail
116+
117+
Automatically crop it using the smart cropper in a square aspect ratio at 50% quality:
118+
119+
~~~ html
120+
<txp:image name="wolverine.jpg" thumbnail="2" width="500" crop="1:1.smart" quality="50" />
121+
~~~
122+
123+
If the thumbnail of that particular image is already set as 'automatic' then the `thumbnail` attribute value can be omitted (i.e. `thumbnail` can be used on its own).
124+
105125
## Genealogy
106126

127+
### Version 4.9.0
128+
129+
`crop` attribute added. \\
130+
`thumbnail` supports `2` (automatic).
131+
107132
### Version 4.8.3
108133

109134
`loading` attribute added.

0 commit comments

Comments
 (0)