From The Ticket Wiki - UnWikit
Jump to: navigation, search

Page from MediaWiki

This page explains the image syntax when editing the wiki. You or another user must usually upload an image before you can use it on a page.

Images that are stored on a MediaWiki server are usually rendered by using the File: namespace prefix (but the legacy Image: namespace prefix is still supported as a synonym) as the target of a MediaWiki link.

The alternate Media: namespace prefix is also usable to reference the original media file content (for rendering or downloading it separately, out of any MediaWiki page).

Supported media types for images

The following file formats are supported by default:

  • .jpg or .jpeg : bitmap image compressed in the standard JPEG format (this lossy format is most suitable for photographs).
  • .png : bitmap image in the Portable Network Graphics format (specified by the W3 Consortium).
  • .gif : bitmap image in the legacy Graphics Interchange Format.

Other formats used on Wikimedia, and commonly enabled elsewhere (these may require extra set-up beyond what is enabled by default):

  • .svg : scalable image in the Scalable Vector Graphics format (specified by the W3 Consortium).
  • .tiff : Tagged image format. Often used for high-resolution archival photographs.
  • .ogg, .oga, .ogv : Ogg multimedia (audio or video). Not an image format, but treated similarly.
  • .pdf : multipaged documents in the Portable Document Format (initially specified by Adobe).
  • .djvu : multipaged bitmap documents in the DejaVu format (most often, scans of books).
    Only a single page of a .pdf or .djvu file is shown at one time.

Other media types may be supported, but it may not be possible to display them inline.

Rendering a single image


The full syntax for displaying an image is: [[File:filename.extension|options|caption]]

where options can be zero or more of the following, separated by pipes (|):

  • Format option: one of border and/or frameless, frame, thumb (or thumbnail);
    Controls how the rendered image is formatted and embedded in the rest of the page.
  • Resizing option: one of
    • {width}px — Resizes the image to fit within the given maximum width in pixels, without restricting its height;
    • x{height}px — Resizes the image to fit within the given maximum height in pixels, without restricting its width;
    • {width}x{height}px — Resizes the image to fit within the given width and height in pixels;
    • upright — Resizes an image to fit within reasonable dimensions, according to user preferences (suitable for images whose height is larger than width).
    Note that the image will always retain its aspect ratio, and can only be reduced (not increased) in size unless it's in a scalable media type (bitmap images cannot be scaled up).
    The default maximum size depends on the format and the internal image dimensions (according to its media type).
  • Horizontal alignment option: one of left, right, center, none;
    Controls the horizontal alignment (and inline/block or floating styles) of the image within a text (no default value).
  • Vertical alignment option: one of baseline, sub, super, top, text-top, middle, bottom, text-bottom;
    Controls the vertical alignment of a non-floating inline image with the text before or after the image, and in the same block (the default vertical alignment is middle).
  • Link option: one of
    • link={target} — Allows to change the target (to an arbitrary page title, or URL) of the generated link, activable on the rendered image surface; e.g. [[File:Example.jpg|20px|link=]] renders as Example.jpg (external link), or [[File:Example.jpg|20px|link=MediaWiki]] renders as Example.jpg (internal link).
    • link= (with an empty value) — (MediaWiki 1.14+) Displays an image without any activable link; e.g. [[File:Example.jpg|20px|link=]]</> renders as Example.jpg</>.
  • Other specific options:
    • alt={alternative text} — (MediaWiki 1.14+) Defines the alternative text (maps to the HTML attribute alt="..." of the generated <img /> element) of an image that will be rendered if either the referenced image cannot be downloaded and embedded, or if the support media must use the alternative description text (e.g. when using a Braille reader or with accessibility options set by the user in its browser).
    • page={number} — Renders the specified page number (currently only applicable when showing a .djvu or .pdf file).
    • class={html class} — (MediaWiki 1.20+) Defines classes (maps to the HTML attribute class="..." of the generated <img /> element).
    • lang={language code} — (MediaWiki 1.22+) For SVG files containing <switch> statements varying on a systemLanguage attribute, selects what language to render the file in. The default is always English, even on non-English wikis.

If a parameter does not match any of the other possibilities, it is assumed to be the caption text.

Caption text shows below the image in thumb and frame formats, or as tooltip text in any other format.

Caption text displayed in the thumb and frame formats may contain wiki links and other formatting.

MediaWiki extensions can add additional options.

If 'alt' is not specified and a caption is provided, the alternative text will be created automatically from the caption, stripped of formatting.


The following table shows the effect of all available formats.

When the height of an image in thumbnail is bigger than its width (i.e. in portrait orientation rather than landscape) and you find it too large, you may try the option upright=N, where N is the image's aspect ratio (its width divided by its height, defaulting to 0.75). The alternative is to specify the desired maximum height (in pixels) explicitly.

Note that by writing thumb={filename}, you can use a different image for the thumbnail.

Size and frame

Among different formats, the effect of the size parameter may be different, as shown below.

  • For how it appears when its size is not specified, see Format section above.
  • When the format is not specified, or only bordered, the size can be both reduced and enlarged to any specified size.
  • In the examples below, the original size of the image is 400 × 267 pixels.
  • An image with frame always ignores the size specification, the original image will be reduced if it exceeds the maximum size defined in user preferences.
  • The size of an image with thumb can be reduced, but can not be enlarged beyond the original size of the image.

Horizontal alignment

Note that when using the frame or thumb[nail] formats, the default horizontal alignment will be right.

Description You type You get
no horizontal alignment specified, or default alignment

Rendered as a floating block: no Rendered inline: yes

... text text text [[File:example.jpg|100px|caption]] text text text ... ... text text text

caption text text text ...

specify horizontal alignment as: none

Rendered as a floating block: no Rendered inline: no

... text text text [[File:example.jpg|none|100px|caption]] text text text ... ... text text text

text text text ...

specify horizontal alignment as: center

Rendered as a floating block: no Rendered inline: no

... text text text [[File:example.jpg|center|100px|caption]] text text text ... ... text text text

text text text ...

specify horizontal alignment as: left

Rendered as a floating block: yes Rendered inline: no

... text text text [[File:example.jpg|left|100px|caption]] text text text ... ... text text text

text text text ...

specify horizontal alignment as: right

Rendered as a floating block: yes Rendered inline: no

... text text text [[File:example.jpg|right|100px|caption]] text text text ... ... text text text

text text text ...

Stopping the text flow

On occasion it is desirable to stop text (or other inline non-floating images) from flowing around a floating image.

Depending on the web browser's screen resolution and such, text flow on the right side of an image may cause a section header (for instance, == My Header ==) to appear to the right of the image, instead of below it, as a user may expect.

The text flow can be stopped by placing <br clear=all> (or if you prefer, <div style="clear: both"></div>) before the text that should start below the floating image.

(This may also be done without an empty line by wrapping the section with the floating images with <div style="overflow: hidden">…</div>, which clears all floats inside the div element.)

All images rendered as blocks (including non-floating centered images, left- or right-floating images, as well as framed or thumbnailed floating images) are implicitly breaking the surrounding lines of text (terminating the current block of text before the image, and creating a new paragraph for the text after them).

They will then stack vertically along their left or right alignment margin (or along the center line between these margins for centered images).

Rendering a gallery of images

Gallery syntax

It's easy to make a gallery of thumbnails with the <gallery> tag. The syntax is: </translate>

File:file_name.ext|caption|alt=alt language
File:file_name.ext|caption|alt=alt language

Note that the image code is not enclosed in brackets when enclosed in gallery tags.

Captions are optional, and may contain wiki links or other formatting. Some of the parameters controlling thumb output can also be used here, specifically the ones that modify the file (as opposed to ones that control where in the page the image falls). For example, with multi-paged media like pdfs, you can use code like page=4.

The File: prefix can be omitted.

For example:

<gallery> File:Example.jpg|Item 1 File:Example.jpg|a link to [[Help:Contents]] File:Example.jpg File:Example.jpg|alt=An example image. It has flowers File:Example.jpg|''italic caption'' Example.jpg|on page "{{PAGENAME}}" </gallery>

is formatted as:

Mode parameter

Starting in Mediawiki version 1.22, we have an experimental mode parameter, taking options as follows:

  • traditional is the original gallery type used by MediaWiki.
  • nolines is similar to traditional, but with no border lines.
  • packed causes images to have the same height but different widths, with little space between the images. The rows in this responsive mode organize themselves according to the width of the screen.
  • packed-overlay shows the caption overlaid on the image, in a semi-transparent white box.
  • packed-hover is similar to packed-overlay, but with the caption and box only showing up on hover.

For example:



Optional gallery attributes

The gallery tag itself takes several additional parameters, specified as attribute name-value pairs:

<gallery {parameters}>
  • caption="{caption}": (caption text between double quotes for more than a word) sets a caption centered atop the gallery.
  • widths={width}px: sets the widths of the images, default 120px.

Note the plural, widths.

  • heights={heights}px: sets the (max) heights of the images.
  • perrow={integer}: sets the number of images per row. 0 means automatically adjust based on width of screen.
  • showfilename={anything}: Show the filenames of the images in the individual captions for each image (1.17+).
  • mode={traditional|nolines|packed|packed-hover|packed-overlay}: See section above (1.22+).
The widths and heights parameters are taken more as suggestions than strict values for packed (and related) modes. Packed modes will adjust the width of images in order to make each row the same length.



<gallery widths=60px heights=60px perrow=7 caption="sunflowers are groovy">


Row of images that will wrap to browser width

One way that works for a row of images with varying widths is not to use "thumb" or "left" or "none".

If "thumb" is not used (and thus no captions) a row of images will wrap to the browser width.

If necessary, narrow the browser window to see the images wrap to the next row.


Example.jpg Example.jpg Example.jpg Example.jpg Example.jpg Example.jpg Example.jpg

To wrap images of varying widths with captions it is necessary to use div HTML for an unordered list. Along with style="display: inline-block;". For more info and ideas see: Give Floats the Flick in CSS Layouts.

<li style="display: inline-block;"> [[File:Example.jpg|thumb|none|220px|Caption 1]] </li>
<li style="display: inline-block;"> [[File:Example.jpg|thumb|none|100px|Caption 2]] </li>
<li style="display: inline-block;"> [[File:Example.jpg|thumb|none|150px|Caption 3]] </li>
<li style="display: inline-block;"> [[File:Example.jpg|thumb|none|250px|Caption 4]] </li>
<li style="display: inline-block;"> [[File:Example.jpg|thumb|none|200px|Caption 5]] </li>
<li style="display: inline-block;"> [[File:Example.jpg|thumb|none|220px|Caption 7]] </li>
<li style="display: inline-block;"> [[File:Example.jpg|thumb|none|175px|Caption 8]] </li>
  • Caption 1
  • Caption 2
  • Caption 3
  • Caption 4
  • Caption 5
  • Caption 7
  • Caption 8

Some wiki farms do not have all gallery options (such as "widths"). Also, sometimes one wants varying widths for images in a row. Outside of a gallery, or the div HTML, it is impossible to have individual captions for images in a row of images that will wrap to the browser width. Try it and see. Nothing else using wikitext works correctly. Images will either overlap stuff on the right, or force a horizontal scroll bar.

Using a left float ("left") for some images, combined with "none" for some of the images, will not work consistently either, especially if there is also a right sidebar of images. Weird things will occur. At narrower browser or screen widths an image out of the row may appear far down the page after the end of the right sidebar of images.

Link behavior

By default an image links to its file description page. The "link=" option modifies this behavior to link to another page or website, or to turn off the image's linking behavior.

Alternatively, you can create a text link to a file description page or to the file itself. See Help:Linking to files.

Display image, link it to another page or website

Use "link=" option to link image to another page or website:

Clicking on the below image will take you to [1]:



Clicking on the below image will take you to



Display image, turn off link

Use "link=" option with no value assigned to turn link off entirely; the below image is not a link:




Before using images in your page, the system administrator of your wiki must have enabled file uploads and a user has to upload the file. System administrators may also set the wiki to accept files from foreign repositories, such as the Wikimedia Commons. For server side image resizing it is necessary to have a scaler configured (such as GD2, ImageMagick, etc.).

Files at other websites

You can link to an external file available online using the same syntax used for linking to an external web page. With these syntaxes, the image will not be rendered, but only the text of the link to this image will be displayed.


Or with a different displayed text:

[http://url.for/some/image.png link text here]

Additional MediaWiki markup or HTML/CSS formatting (for inline elements) is permitted in this displayed text (with the exception of embedded links that would break the surrounding link):

[ Example '''<del>rich</del>''' ''<ins>link text</ins>'' here.]

which renders as: Example rich link text<ins> here.

If it is enabled on your wiki, you can also embed external images. To do that, simply insert the image's url: </translate>


Currently, embedded images cannot be resized, but they may be formatted by surrounding MediaWiki markup or HTML/CSS code.

If this wiki option is not enabled, the image will not be embedded but rendered as a textual link to the external site, just like above.

See also