Wikipedia:Wikipedia Signpost/2008-03-03/Tutorial

{{Tutorials}}

{{Wikipedia:Wikipedia Signpost/Templates/Signpost-article-header-v2 |{{{1|Tutorial: How to use an ImageMap}}}|By Nihiltres}}

This week's tutorial explains the syntax for the ImageMap extension of the MediaWiki software, which allows images and sections thereof, of any shape and size, to link to any type of page link that can be linked to via text (any valid wikilink, interwiki link, or external link).

A basic understanding of image syntax is assumed.

= When to use ImageMap =

An ImageMap does not behave the way a normal image does, where clicking anywhere on an image opens its image description page. Instead, with an ImageMap, clicking on the image is the equivalent of clicking on a link; different sections of the image may link to different pages, including external links. ImageMap should generally only be used with free images (that is, those that do not fall under the non-free content criteria), because creating an ImageMap can be regarded as a substantial modification of an image.

ImageMaps are generally used within templates, where it is desirable to have images or icons link to particular pages or sections of a page, and in portals, where it links icons for related portals to that portal and links the logos of various projects in the interwiki section to their respective projects. If ImageMap does not add to the presentation of a template, portal, or article, it should probably not be used, since the ideal behaviour—for transparency with image licensing—is to have the image link to the description page.

To summarize:

:#If the image is non-free content, it is advisable to not use ImageMap.

:#If ImageMap would not add significantly to the presentation of the page upon which it is used, one should probably not use ImageMap on that page.

= Creating an ImageMap =

To create an ImageMap, one can use either the tags and , or the magic word (and ParserFunction) {{#tag:imagemap|   }}. The format is generally preferable (a good practice) for simple ImageMaps, but does not (currently) function properly with template parameters, magic words, or ParserFunctions. In this case, the {{#tag}} format is a simple and effective workaround, which replaced older, usability-troublesome CSS workarounds for templates that created images linked to alternate pages, such as {{click}}.

To summarize:

:#There are two syntactically correct containers for ImageMap syntax: and , or {{#tag:imagemap| and }}.

:#The former is best practice, but only the latter allows the use of template parameters, magic words, and ParserFunctions.

= The image line =

The first line of any ImageMap must be a line specifying the image being used. If no image is specified, or the image that is specified does not exist, then the ImageMap will produce the following error message:

:

Image:NoSuchImage.svg|100px|This is an example of the nonexistent-image error.

default User:Nihiltres

desc none

Note, however, that there must be a linebreak after the imagemap tag (of either form) and before this line. This image code is identical in syntax to normal image syntax, albeit without the surrounding square brackets ( ). All of the basic image syntax and extended image syntax applies, though options such as thumb may not be fully supported by ImageMap. The text provided as a comment in the image syntax on this line is not visible except as alternative text when the image is unavailable, except for options such as thumb which might use it.

:For example, in the case that the syntax for the normal, unmapped image was 100px, the ImageMap code for the first line would be

:Image:WikipediaSignpostHead.svg|100px

To summarize:

:#Construct the image syntax normally

:#Remove the and from around the image syntax

:#Use the resulting text as the image line

= The image description icon =

Since images should, as a good practice, include a link to the image description page, ImageMap includes, by default, an information icon on the image linking to the image description page. This by default displays on the bottom-right of an image, but can be changed by using desc and a location: any of top-right, bottom-right, bottom-left, top-left, or none to disable it completely.

:The desc parameter allows you to change the location of the information icon, or disable it.

::For example, the following would be a valid line disabling the description icon:

::desc none

= Overview =

Once all of the elements have been determined, they can be placed within the container of choice, separated by linebreaks. The following ImageMap demonstrates valid syntax:

File:Bad Title Example.png|275px|border|This is used as alternate text.

  1. Note that in the above line, the border style is invoked.
  1. Polygons appear first in the code, always.

poly 14 186 25 219 52 219 63 186 [http://www.wikipedia.org This link is polygon-shaped, and uses an external link.]

rect 107 32 256 182 This rectangle links to the Earth article.

circle 85 135 12 This area is a circle.

desc none

The code produces the following:

File:Bad Title Example.png|275px|border|This is used as alternate text.

  1. Note that in the above line, the bordered style is invoked.
  1. Polygons appear first in the code, always.

poly 14 186 25 219 52 219 63 186 [http://www.wikipedia.org This link is polygon-shaped, and has an external link rather than an internal one.]

rect 107 32 256 182 This rectangle links to the Earth article.

circle 85 135 12 This area is a circle.

desc none

= Resources =

The following are helpful tools related to ImageMap:

  • For complex shapes and graphical editing, it is easiest to use [http://tools.wikimedia.de/~dapete/ImageMapEdit/ImageMapEdit.html?en the graphical ImageMap creator on the toolserver].
  • For easy conversion of the {{click}} template format to ImageMap, it is easy for Mac users to use Nihiltres' conversion tool, which is written in AppleScript. With the advent of the #tag ParserFunction, which allows ImageMaps to receive template parameters and magic words, this isn't very important as {{click}} is no longer a usability problem, but the script may still be useful, if rough.
  • The {{click}} template is a relatively easy way to use ImageMap in template form.
  • For reference information about the ImageMap extension to MediaWiki, see the extension's description page.
  • The Wikipedia article about image maps.

{{Wikipedia:Wikipedia Signpost/Templates/Footer|{{BASEPAGENAME}}|2008-02-18|2008-03-13|{{SUBPAGENAME}}}}

03 Tutorial

{{Wikipedia:Wikipedia Signpost/Templates/Signpost-article-end-v2}}

{{Wikipedia:Signpost/Template:Signpost-article-comments-end|||}}