Template:ImageWidth
The {{ImageWidth}} template computes a reduced width for an image according to two constraints (a minimum if possible, and an absolute maximum) that will be respected on each of the dimensions (width and height) of an image whose dimensions are provided in parameters. In any case, the returned width will never exceed the effective image width and cause it to be increased in size with poor rendering.
The typical usage of this template is for scaling a series of "Pictures of the day", instead of using a fixed width (ideally 252px because this multiple of 12 reduces scaling artefacts for most images with exact aspect ratio 2:3 or 3:4, but it should remain between 250 and 350px) which often produces incorrectly scaled images, or images that much too high or too small in height (notably panoramic images). One could compute an adjusted size, but if the constraints are changed, all images whose size have been specifically adjusted must be readjusted to respect the new constraint. Also, such reduction is often difficult to adjust manually and often results in wrong sizes.
With this template, the constraints are specified externally, and tagging the image is much simpler, as we only specify its native size.
Usage
[edit]Syntax
[edit]{{ImageWidth|w=
native width|h=
native height}}
{{ImageWidth|w=
native width|h=
native height|min=
recommanded minimum|max=
absolute maximum}}
Mandatory parameters
[edit]w=
(or l=)- The native image width in pixels, as it is displayed in its information page for its best resolution (or its default width displayed for an SVG image).
h=
- The native image height in pixels, as it is displayed in its information page for its best resolution (or its default height displayed for an SVG image).
Optional parameters
[edit]min=
- Minimum dimension in pixels to respect, both in width and in height (if possible, unless this would resize the image to a larger size with poor rendering). Default value: 252.
max=
- Maximum absolute dimension in pixels to respect, both in width and height (this should always be the case). Default value: 348.
- Note: in some cases, only with images in portrait format which are more than twice taller than their width, the effective height that will be created from images may exceed this absolute maximum by a few pixels, or may not reach this theoretical maximum, because of the final rounding to the nearest integer computed for the width returned by this template; however, the difference in pixels with this theoretical maximum will never exceed the half of the native height/width ratio.
Examples
[edit]- Cases that cause reduction of big native image sizes (using defaults
min=252|max=348
) - reducing width to its maximum allowed (height will be lower than the preferred minimum):
{{ImageWidth|w=3400|h= 600}}
returns 348 (panoramic horizontal image){{ImageWidth|w=3200|h=1600}}
returns 348 (2:1 landscape image){{ImageWidth|w=3000|h=2000}}
returns 348 (3:2 landscape image)
- reducing width in interval, but set height to its minimum allowed:
{{ImageWidth|w=2800|h=2100}}
returns 336 (4:3 landscape image){{ImageWidth|w=2600|h=2400}}
returns 273 (nearly square landscape image)
- reducing width and height to their minimum allowed:
{{ImageWidth|w=2520|h=2520}}
returns 252 (1:1 square image)
- reducing height in interval, but set width to its minimum allowed:
{{ImageWidth|w=2400|h=2600}}
returns 252 (nearly square portrait image){{ImageWidth|w=2100|h=2800}}
returns 252 (3:4 portrait image)
- reducing height to its maximum allowed (width will be lower than the preferred minimum):
{{ImageWidth|w=2000|h=3000}}
returns 232 (2:3 portrait image){{ImageWidth|w=1600|h=3200}}
returns 174 (2:1 landscape image){{ImageWidth|w= 600|h=3400}}
returns 61 (panoramic vertical image)
- Cases that leave small native image sizes unchanged (using defaults
min=252|max=348
) -
{{ImageWidth|w=340|h= 60}}
returns 340 (panoramic horizontal image){{ImageWidth|w=320|h=160}}
returns 320 (2:1 landscape image){{ImageWidth|w=300|h=200}}
returns 300 (3:2 landscape image){{ImageWidth|w=280|h=210}}
returns 280 (4:3 landscape image){{ImageWidth|w=260|h=240}}
returns 260 (nearly square landscape image){{ImageWidth|w=252|h=252}}
returns 252 (1:1 square image){{ImageWidth|w=240|h=260}}
returns 240 (nearly square portrait image){{ImageWidth|w=210|h=280}}
returns 210 (3:4 portrait image){{ImageWidth|w=200|h=300}}
returns 200 (2:3 portrait image){{ImageWidth|w=160|h=320}}
returns 160 (1:2 portrait image){{ImageWidth|w= 60|h=340}}
returns 60 (panoramic vertical image)
See also
[edit]- The French Wikipedia now uses a French translation of this template to correctly scale its images Image du jour (imported from the collection of "Pictures of the Day" selected on Commons) displayed on its front page.