Template:ImageWidth/doc

The   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.

Syntax

 *  
 *  

Mandatory parameters

 * 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

 * 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

 * 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):
 *   returns  (panoramic horizontal image)
 *  </tt> returns  (2:1 landscape image)
 *  </tt> returns  (3:2 landscape image)
 * reducing width in interval, but set height to its minimum allowed:
 *  </tt> returns  (4:3 landscape image)
 *  </tt> returns  (nearly square landscape image)
 * reducing width and height to their minimum allowed:
 *  </tt> returns  (1:1 square image)
 * reducing height in interval, but set width to its minimum allowed:
 *  </tt> returns  (nearly square portrait image)
 *  </tt> returns  (3:4 portrait image)
 * reducing height to its maximum allowed (width will be lower than the preferred minimum):
 *  </tt> returns  (2:3 portrait image)
 *  </tt> returns  (2:1 landscape image)
 *  </tt> returns  (panoramic vertical image)


 * Cases that leave small native image sizes unchanged (using defaults min=252|max=348</tt>)
 *  </tt> returns  (panoramic horizontal image)
 *  </tt> returns  (2:1 landscape image)
 *  </tt> returns  (3:2 landscape image)
 *  </tt> returns  (4:3 landscape image)
 *  </tt> returns  (nearly square landscape image)
 * <tt> </tt> returns  (1:1 square image)
 * <tt> </tt> returns  (nearly square portrait image)
 * <tt> </tt> returns  (3:4 portrait image)
 * <tt> </tt> returns  (2:3 portrait image)
 * <tt> </tt> returns  (1:2 portrait image)
 * <tt> </tt> returns  (panoramic vertical image)