Extension:EImage

The EImage extension allows users to display images hosted on external image hosts (currently only Imgur and Flickr) as if they were stored locally. External images may be thumbnailed/resized/framed just like local images and the syntax used is very similar to MediaWiki's Images syntax. Another feature is the ability to overlay text on top of images (based on Template:Annotated image).

EImage queries image hosts' APIs in order to obtain image metadata such as dimensions and comments/descriptions. It uses the dimensions to preserve aspect ratio when users scale images by height, and it helps avoid maintaining image descriptions on both the image hosts' website AND the Wiki article. Since most image hosts have a limit of how many times they may be queried for data every hour, EImage caches data in the Wiki's database.

Installation
require_once( "$IP/extensions/EImage/EImage.php" );
 * Download and extract the files to your extensions/ folder. It will automatically create the "EImage" folder.
 * Add the following code to your LocalSettings.php (at the bottom)
 * Done - Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Configuration parameters

 * $wgEImageApiKeyImgur: Authenticated API key for Imgur (for double the credits). Default is blank, using the Anonymous API. http://api.imgur.com/#authapi
 * $wgEImageApiKeyFlickr: API key for Flickr. If this is not set, Flickr support will be disabled. An API key is mandatory. http://www.flickr.com/services/api/
 * $wgEImageStaleMinutes: Refresh cached metadata if the stored entry is this many minutes old. Default is 60.

Syntax and Examples
EImage has three types of options:
 * Image: The "main" options for displaying the image. This is similar to MediaWiki's Images.
 * Annotation Defaults: Default options that are applied to all annotations in the image.
 * Annotations: This is a separate parser function for an annotation. You can have as many of these as you want.

Image
The full syntax for displaying an image is:

Refer to http://www.mediawiki.org/wiki/Help:Images for detailed descriptions. Below is a list of options available in EImage:
 * Image option: the ID (not URL/filename) of the image to display
 * Imgur usually has 5-character alphanumeric image IDs (e.g. KO5Za) and Flickr has 10-digit image IDs (e.g. 8055532325).
 * Host option: either imgur or flickr
 * If neither are specified, defaults to imgur.
 * Format option: one of border and/or frameless, frame, thumb
 * Resizing option: one of
 * {width}px
 * x{height}px
 * {width}x{height}px
 * Horizontal alignment option: one of inline and/or left, right, center, none
 * The inline option displays the image(+frame) inline instead of as a floating block (it overrides the float option). Works best with none. Useful for displaying multiple thumbnails on one line.
 * Vertical alignment option: one of baseline, sub, super, top, text-top, middle, bottom, text-bottom
 * Link option: one of
 * link={target}
 * link=
 * Currently only external links that start with http/https/ftp are supported.
 * Other specific options:
 * alt={alternative text}

If a parameter does not match any of the other possibilities, it is assumed to be the caption text. Captions support wiki-formatting. EImage will also replace any instance of !!TITLE!! or !!COMMENT!! with the title/subject metadata and with the comments/description metadata from the image host respectively. The same thing applies to alt=.

Some examples:

Annotation Defaults
These options change the defaults for all annotations in an image (not all images). If no annotations are used, these are ignored:
 * Horizontal alignment option: aalign=
 * Background color option: abg=
 * Default is transparent
 * Font family option: afamily=
 * Font size option: asize=
 * Font weight option: aweight=
 * Font style option: astyle=
 * Font shadow option: ashadow=
 * Font color option: acolor=
 * Line height option: aheight=

Annotations
Each image can have any number of annotations. In the tag use the annot= option to specify an annotation. The value of annot= is another function called . Below are the options available for :
 * Horizontal alignment option: one of left, right, center, justify, inherit
 * Background color option: bg=
 * Font family option: family=
 * Font size option: size=
 * Font weight option: weight=
 * Font style option: style=
 * Font shadow option: shadow=
 * Font color option: color=
 * Line height option: height=

If a parameter does not match any of the other possibilities, it is assumed to be the annotation text. Annotations support wiki-formatting.

Some examples:

Credits
These are the sources I used for inspiration, ideas, and code.
 * http://en.wikipedia.org/wiki/Template:Annotated_image
 * http://code.fivefilters.org/php-readability/src/15782b1b8ee4/JSLikeHTMLElement.php
 * A very big help with converting links common in Flickr comments to wiki-formatted links
 * https://svn.wikia-code.com/vendor/mediawiki/REL1_19/extensions/SelectionSifter/schema/ratings.sql