Wikipedia:Extended image syntax: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Michael Daly (talk | contribs)
→‎Link: Add empty "link=" format documentation.
Michael Daly (talk | contribs)
→‎Link: clarify.
Line 44: Line 44:
* "'''link='''''page name''": The image will act as a hypertext link to the specified page. The page name must not be enclosed in square brackets, and it is always interpreted as an internal link.
* "'''link='''''page name''": The image will act as a hypertext link to the specified page. The page name must not be enclosed in square brackets, and it is always interpreted as an internal link.
* "'''link='''": No hyperlink is is created. Clicking on the image will have no action.
* "'''link='''": No hyperlink is is created. Clicking on the image will have no action.
* Note that link cannot be used in conjunction with ''thumb'' as thumb is always meant to link to the larger version of the image. In addition, link cannot be used with ''frame''.


===Text===
===Text===

Revision as of 02:17, 5 July 2009

In brief, the syntax for displaying an image is:

[[Image:{name}|{type}|{location}|{size}|{upright}|{link}|{text}]]

Only [[Image:{name}]] is required. Most images should use [[Image:{name}|thumb|Example image caption]] (and should not specify a size). The other details are optional and can be placed in any order.

Type
'thumb' / 'thumbnail', 'frame', or 'border'. Causes image to be displayed with specific formatting (see below).
Location
'right', 'left', 'center' or 'none'. Determines placement of the image on the page. Defaults to 'right'.
Size
{width}px or {width}x{height}px, scales the image to be no greater than the given width and height, keeping its aspect ratio.
Upright
intended for use on images that are taller than they are wide; must be used along with the 'thumb' or 'thumbnail' parameter. This scales the image to approximately 80% of thumbnail width. A parameter can be added to adjust the size: for instance "upright=1.5" will make the image larger, useful for maps or schematics that need to be larger to be readable. The parameter "upright=1" returns the same size as thumbnail width; "upright=.8" is functionally identical to "upright" alone.
Link
Specifies that the image should act as a link to a different page.
Text
Specifies the alt text, title text, or caption for the image.

It does not matter whether the file is from Wikimedia Commons or on Wikipedia; the same syntax is used.

Detailed syntax

Type

Zero or one of these options may be specified to control whether or not the image is scaled down and given a border.

  • "thumbnail" or "thumb": Image is scaled down, and a box is added around the image. If a caption is written, it is shown below the image. Image defaults to placement on the 'right' unless overridden with the 'Location' attribute (see above). The scaled image size may be specified in another option (see "Size" below), failing which a per-user preference will be used for logged-in users (see "thumbnail size" in Special:Preferences), or the default thumbnail size of 180 pixels will be used for non-logged-in users.
    Thumbnailing animated GIFs is not supported. Thumbnailing an animated GIF does not result in an error, so there is no warning, but the animated GIF is not processed. Instead the original animated GIF is shipped, and whether the animated GIF is subsequently scaled to fit the allotted space is down to the capabilities of the receiving browser.
  • "frame": Original image size is preserved, and a box is added around the image. If a caption is written, it is shown below the image. Sizing does not work when |frame| is used.
  • (nothing specified): Original image size is preserved, no border is added around the image. Even if a caption is requested, it is not shown. If no alt text is specifically requested, then the requested caption will be used as alt text.
  • "border": Same as if nothing is specified, but a border is added around the image.

Location

Zero or one of these options may be specified to control the position of the image.

  • "right": Image including its box is placed on the right side of the page. The article text that follows the image flows around the image.
  • "left": Image including its box is placed on the left side of the page. The article text that follows the image flows around the image.
  • "center": Image including its box is placed in the center of the page. The article text that follows the image is placed below the image.
  • "none": Image including its box is placed on the left side of the page. The article text that follows the image is placed below the image.

Size

Zero or one of these options may be specified to control the size of the image. In the case of images with captions, if the image is already smaller than the requested size, then the image retains its original size (it is not enlarged). In the case of images without captions, the image will be enlarged or reduced to match the requested size.

  • "widthpx" (e.g. "100px"): Scales the image to make it the specified number of pixels in width. The height is also scaled in such a way as to retain the original aspect ratio.
  • "widthxheightpx" (e.g. "100x150px"): Scales the image to be no wider and no higher than the specified number of pixels. The image will keep its original aspect ratio.
  • (nothing specified): Uses the size specified in preferences for logged in users, uses a size determined by resolution for anonymous users.

Resizing animated GIFs is not supported. Resizing an animated GIF does not result in an error, so there is no warning, but the animated GIF is not processed. Instead the original animated GIF is shipped, and whether the animated GIF is subsequently scaled to fit the allotted space is down to the capabilities of the receiving browser.

Link

Ordinarily, an image acts as a hypertext link to the image description page, a page with information about the image itself. Using the link option allows an image to act as a hypertext link to a different page. See Wikipedia:Images linking to articles for more information.

  • "link=page name": The image will act as a hypertext link to the specified page. The page name must not be enclosed in square brackets, and it is always interpreted as an internal link.
  • "link=": No hyperlink is is created. Clicking on the image will have no action.
  • Note that link cannot be used in conjunction with thumb as thumb is always meant to link to the larger version of the image. In addition, link cannot be used with frame.

Text

Zero or more of these options may be specified to control the alt text, title text, and caption for the image. The text may contain embedded wiki markup, such as links or formatting. See Wikipedia:Captions for discussion of appropriate caption text. See Wikipedia:Alternative text for images for discussion of appropriate alt text.

  • "alt=alt text": The specified text will be used as the alt text for the image.
  • "caption or alt text" (any text that is not recognised as some other part of the image syntax): The specified text is used as a caption, or as alt text, depending on the image type. For thumbnail, thumb, or frame image types, the specified text will be used as a caption. For other image types, the specified text will be used as alt text (unless the alt text is specified explicitly via the "alt=" option, in which case the text specified here will be ignored).

The actual alt text for the displayed image will be one of the following, in order of preference:

  1. The explicitly requested alt text, if any;
  2. The requested caption or alt text, if the image has no caption;
  3. The empty string, if the image has a caption

The actual title text for the hypertext link surrounding the image will be one of the following, in order of preference:

  1. The requested caption or alt text, if any;
  2. The empty string, if no caption or alt text is requested.

How to display an image in uploaded size, with a caption

To display an image as uploaded with a caption use [[Image:Westminstpalace.jpg|frame|none|caption text]]. Type the following to update images that used the original image markup of the form [[Image:Westminsterpalace.jpg|caption text]].

caption text

How to display an images with no caption or formatting

The old syntax for images without captions is [[Image:Westminstpalace.jpg|alt text]]. This is rendered inline, and the specified text is used as the image's alt attribute (alternate text for programs which cannot display images, such as screen readers) and as the title attribute (supplementary text, often displayed as a tool tip when the mouse is over the image).

See Wikipedia:Image markup with HTML for an old, deprecated, way of putting a caption under the image using HTML code. Please use the new way of associating captions with images, as described on this page.

See Wikipedia:Captions for discussion of appropriate caption text. See Wikipedia:Alternative text for images for discussion of appropriate alt text.

Example

alt text

New syntax for images

The Palace of Westminster

The new syntax is backward compatible, so articles don't have to be changed. In the syntax [[Image:filename|options]] (e.g. [[Image:Westminstpalace.jpg|thumb|100px|left|The Palace of Westminster]] shown in the left), several options can be set when including an image. Those affect the placing of the image, its size or the way the image will be presented. The options are right, left, center, none, sizepx, thumbnail (thumb), frame, and alternate (caption) text.

From the Thames
  • The options can be combined, and vertical bars ("|") are used to separate options from each other.
  • Do not put spaces around the vertical bars for readability – options will not be interpreted correctly.
  • The options can be put in any order.
  • An unknown option is taken as the caption text, but this will appear only if thumbnail or frame are specified.
  • If there are two or more unknown options, the last one upstages the rest: [[Image:Westminstpalace.jpg|thumb|The Palace of Westminster|200px|right|From the Thames]] (shown on the right).

Here is the description of the options other than the caption text:

right

The image is right-aligned, and text floats to the left of the image: [[Image:Westminstpalace.jpg|right|70px|]] (shown on the right).


left

The image is left aligned, and text floats to the right of the image: [[Image:Westminstpalace.jpg|left|70px|]] (shown on the left).


center

The image is centered, and...

the text following the image starts below it: [[Image:Westminstpalace.jpg|center|70px|]] (shown above).


none

The image is put at the left, and...

the text following does not float to the right (or to the left, obviously), and starts below it: [[Image:Westminstpalace.jpg|none|70px|]] (shown above).


Notes:
The above four options are incompatible. When used combined, the first one overrides the rest: [[Image:Westminstpalace.jpg|center|left|none|right|70px|]] (shown in the center).
What is between the last vertical bar and the closing brackets ("]]"), void or not, is taken as the last option, and works as usual. For instance, when the last option is right, the image is right-aligned, and text floats to the left: [[Image:Westminstpalace.jpg|70px|right]] (shown on the right).
This text is displayed.
In particular, if the last option is the void text (that is, if there is nothing between the last vertical bar and the closing brackets), the caption is not displayed: [[Image:Westminstpalace.jpg|thumb|This text is not displayed.|70px|left|]] (shown on the left) and [[Image:Westminstpalace.jpg|thumb|This text is displayed.|70px|right]] (shown on the right).
sizepx
This option renders a version of the image that's [size] pixels wide (e.g. [[Image:Westminstpalace.jpg|right|50px|]] shown on the right). Height is computed to keep (i.e. the shape of the image)
Notes:
Specifying a size does not just change the apparent image size using HTML; it actually generates a resized version of the image on the fly and links to it appropriately. This happens whether or not you use size in conjunction with thumb.
This means the server does all the work of changing the image size, not the web browser of the user. By having the server do all the work means faster downloading of pages. It also means that larger images can be stored on the server without any slowdown by the browser (especially on dial up telephone lines.) Only the data for the actual size on the page is transmitted.
An exception is animated GIF. Animated GIFs are not processed by the server. When a smaller size is specified the original full sized animated GIF is served. Whether the animated GIF is subsequently scaled to fit the allotted space is down to the capabilities of the receiving browser. Resizing an animated GIF will significantly reduce its quality, without any reduction of download time.
From MediaWiki 1.5 the default thumbnail width can be set in the preferences, so it is recommended not to specify "px", in order to respect the users' preferences (unless, for a special reason, a specific size is required regardless of preferences, or a size is specified outside the range of widths 120–300px that can be set in the preferences).
If you specify a "frame" option the image will not be scaled, and no size specifiers will be in the HTML. The image will be rendered at full size
When there are two or more "size" options, only the last one is valid: [[Image:Westminstpalace.jpg|right|50px|80px]] (shown on the right).
thumbnail, thumb
The Palace of Westminster
The thumbnail (thumb) option generates a image. It is automatically resized when the "size" attribute is not specified. Without the options left, center, and none, the image is normally on the right. If the image has a caption text, it is displayed in the lower margin. E.g. [[Image:Westminstpalace.jpg|thumbnail|left|100px|]] (shown on the left) and [[Image:Westminstpalace.jpg|thumb|The Palace of Westminster]] (shown on the right). Note: thumbnail (thumb) cannot be used in lists.
This is a globe, and take a look at it in the actual size.

An "enlarge"-icon is put also in the lower margin of the thumbnail. Both the image itself and the icon link to the image description page with the image in its actual size. The icon shows the link title "Enlarge" in its hoverbox, even in cases where this term does not apply, because it leads from the enlarged image to the one with the actual size. E.g. [[Image:tst.png|right|thumb|100px|This is a globe, and take a look at it in [[Media:tst.png|the actual size]].]] (shown on the right).

upright
The 'upright' option is about 80% of thumbnail width
The 'upright=1.5' option
The upright option works in combination with the thumbnail or thumb option to resize an image approximately 80% smaller than a thumbnail. The upright option scales larger or smaller in step with user screen resolution. The relative size can be determined with a multiplier such as upright=x. If x=1 then the image is standard thumbnail width. E.g. [[Image:Westminstpalace.jpg|thumbnail|upright|left|The 'upright' option is 80% of thumbnail width]] (shown on the left) and [[Image:Westminstpalace.jpg|thumb|upright=1.5|right|The 'upright=1.5' option]] (shown on the right).
frame
The Palace of Westminster
With this option, the embedded image is shown with its actual size enclosed by a frame, regardless of the "thumb" or "size" attribute, and the caption, if any, is visible in the frame. Without the options left, center, and none, the image is normally on the right: [[Image:Westminstpalace.jpg|frame|thumbnail|50px|The Palace of Westminster]].

With none of the options other than sizepx and alternate (caption) text, an embedded image is rendered inline.

text text text text text text
[[Image:Westminstpalace.jpg|150px|The Palace of Westminster]]
text text text text text
[[Image:tst.png|100px|This is a globe.]]
text text text text

gives

text text text text text text The Palace of Westminster text text text text text This is a globe. text text text text

The option none can be used to have thumbnails without left- or right-alignment. This is probably most useful for tables. This is an example:

How to use none
London's palaces
Palace of Westminster
From the Thames
[[Image:Westminstpalace.jpg|thumb|none|100px|From the Thames]]
Buckingham Palace
Queen's home
[[Image:Buckingham palace Copyright2003KaihsuTai.jpg|thumb|none|100px|Queen's home]]

Thumbnail with caption text underneath that has one or more links

From MediaWiki 1.3, it is also possible to include links in the caption text, e.g.:

[[Image:Westminstpalace.jpg|right|thumbnail|This is the [[Palace of Westminster]] in London]]

This is the Palace of Westminster in London


Just make sure the number of opening and closing square brackets are right. One extra or missing would mean the entire image syntax line would not work.

Additional caption formatting options

Additional caption formatting options are possible.

[[Image:Westminstpalace.jpg|right|thumbnail|<div align="center">This is <span style="color: green">the </span><br /> [[Palace of Westminster]]<br /> '''in <span style="color: red">London</span>'''</div>]]

This is the
Palace of Westminster
in London


All of the normal text formatting options work.

Compatibility considerations

The floating options left, center, and right explained above are supported by modern browsers, but don't work with older browsers. If necessary it's simple to get a floating effect also for old browsers:

Example
{| align="right"
| [[Image:Westminstpalace.jpg|160px|Example]]
|}

This code is not intended for general use, however. There are few, if any, instances where support for such legacy browsers is necessary.

Cancelling floating-around-image mode

After having had an image floating next to text, putting further text below it and again using the full width can be done with the following markup. This blocks an image from appearing next to the material following this markup, possibly due to aesthetic reasons or a change in topics.

<br style="clear:both" />

For legacy align="right" (etc.) floating this isn't good enough; legacy browsers would ignore inline CSS. To cancel floating under all conditions the following markup (valid XHTML 1.0 transitional) works:

<br clear="all" />

The same code can be issued by using template {{clear}} or {{Clr}} or {{-}} in certain namespaces (En, meta).

Linking to the image description page

If you want to make a link to the description page for an image, use a leading colon before "image:" in an intra-wiki link, like this: [[:image:STS-32 crew.jpg|STS-32 crew]] which yields: STS-32 crew

Images that link somewhere other than the image description page

It is possible to make an image that links to a different page instead of to the image description page. See Wikipedia:Images linking to articles.

Image galleries

See Help:Images and other uploaded files

See also