MTImageInfo Plugin

MTImageInfo Plugin for Movable Type

Version 1.0 by David Phillips (TweezerMan)

Download MTImageInfo plugin - image-info.zip

When a picture is taken, many digital cameras automatically store the camera settings in use (such as time stamp, f/stop, shutter speed, ISO setting, white balance, etc.) as EXIF data within the picture file. The MTImageInfo plugin reads this EXIF data from images on your server and allows you to display it next to the images in your MT weblog. Martin Krzywinski's EXIF: Exchangeable Image File page has more information about EXIF and links to other EXIF resources.

Requirements

Image::Info (version 1.15 or greater)
File::Basename

For best results, images used with this plugin should be in JPEG or TIFF format.

Installation

Unzip mt-imageinfo.zip and copy image-info.pl into your mt/plugins directory.

Tag Reference

<MTImageInfo>

Container tag which identifies image to retrieve EXIF data for. Additionally allows repetitive text/formatting surrounding MTImageInfoField tags to be specified, and whether to display such text/formatting when MTImageInfoField tags are empty or non-existent.

Arguments

img

Required. Specifies the local path/filename of the image to retrieve EXIF data from. The image must reside on the same machine that Movable Type is installed and running on - using a URL (something that begins with "http://") will *not* work.
<MTImageInfo img="/path/to/image.jpg">

The img argument can accept Movable Type tags by enclosing them in [ ] instead of < >:
<MTImageInfo img="[MTBlogSitePath]images/myimage.jpg">

If the embedded tag requires one or more arguments, enclose the value of the argument(s) in single quotes:
<MTImageInfo img="[MTBlogSitePath][MTEntryCategory dirify='1']/myimage.jpg">

leading_text

Optional. Text/html specified in this argument will be output immediately before each MTImageInfoField tag within the container tag.

To include HTML tags within this argument, enclose HTML tag with [ ] in place of < >:
<MTImageInfo img="/path/to/image.jpg" leading_text="[li]">

This argument's text/html is *not* output for empty or non-existent EXIF field values unless show_empty argument is set to "1".

The leading_text argument is ignored for MTImageInfoField tags using name="all".

Default value is "".

trailing_text

Optional. Text/html specified in this argument will be output immediately after each MTImageInfoField tag within the container tag.

To include HTML tags within this argument, enclose HTML tag with [ ] in place of < >:
<MTImageInfo img="/path/to/image.jpg" trailing_text="[br /]">

This argument's text/html is *not* output for empty or non-existent EXIF field values unless show_empty argument is set to "1".

The trailing_text argument is ignored for MTImageInfoField tags using name="all".

Default value is "".

show_empty

Optional. Enables/disables output of leading_text, trailing_text, and MTImageInfoField label argument text/html when an MTImageInfoField value is empty or non-existent.

"0" (default): Text/html specified in leading_text and trailing_text arguments, as well as text/html in an MTImageInfoField label argument, is not output for empty or non-existent MTImageInfoField values.

"1": Outputs text/html in leading_text and trailing_text arguments, as well as text/html in an MTImageInfoField label argument, for all MTImageInfoField tags, including field values that are empty or non-existent.

The show_empty argument is ignored for MTImageInfoField tags using name="all".

<$MTImageInfoField$>

Tag used within MTImageInfo container tag to display EXIF field values from image.

Arguments

name

Required. Outputs value of one EXIF field (except name="all") specified by name. If EXIF field name is not present in image EXIF data, nothing is displayed and no error is generated. Field names are case-sensitive; when in doubt, examine list of field names produced by name="all".

The MTImageInfoField tag can be used multiple times, using different name argument values, to display multiple EXIF fields.

The file name of the image (which includes the extension but no path) can be displayed by using name="filename".

A special case of the name argument is name="all". When name="all" is used, the MTImageInfoField tag will list every EXIF field found in the image along with its value in the format of "FieldName => FieldValue". Using name="all" is useful when you do not know what EXIF fields are present, or are not sure what their exact names are. In that case, use name="all" first to list the fields, note which ones you wish to display, then use separate MTImageInfoField tags (with different name argument values) to display each desired EXIF field.

label

Optional. Text/html specified in this argument is output immediately before EXIF field value.

To include HTML tags within this argument, enclose HTML tag with [ ] in place of < >:
<$MTImageInfoField name="height" label="[strong]Height:[/strong]"$>

This argument's text/html is *not* output for empty or non-existent EXIF field values unless show_empty argument in MTImageInfo container tag is set to "1".

The label argument is ignored for MTImageInfoField tags using name="all".

Default value is "".

format

Optional. If an EXIF field contains a date/time value (in the format of yyyy/mm/dd hh:mm:ss or yyyy:mm:dd hh:mm:ss), you can add a format argument to the MTImageInfoField tag and use MT's date tag formats to specify how you want the date/time displayed.

If no format argument is specified, the blog's default date/time format will be used.

When name="all" is used, EXIF date/time fields are unformatted (format is ignored).

<$MTImageInfoField name="DateTime" format="%a %d %b %Y"$>

Note on EXIF binary fields

EXIF fields containing binary data are generally not decoded and only display "(binary data - xxx bytes)", with "xxx bytes" indicating the size of the binary field. One field that is commonly a binary field is "MakerNotes" and its encoding varies by digital camera manufacturer. The Image::Info Perl module used by this plugin can read some camera model's MakerNotes but not others.

Example 1: Listing all EXIF fields in an image

Template code:

<MTImageInfo img="[MTBlogSitePath]/images/BrokenWindow.jpg">
  <$MTImageInfoField name="all"$><br />
</MTImageInfo>

Sample output:

BitsPerSample => (8, 8, 8)
ColorComponents => ((Y, 34, 0), (Cb, 17, 1), (Cr, 17, 1))
ColorComponentsDecoded => ((ComponentIdentifier => Y, HorizontalSamplingFactor => 2, QuantizationTableDesignator => 0, VerticalSamplingFactor => 2), (ComponentIdentifier => Cb, HorizontalSamplingFactor => 1, QuantizationTableDesignator => 1, VerticalSamplingFactor => 1), (ComponentIdentifier => Cr, HorizontalSamplingFactor => 1, QuantizationTableDesignator => 1, VerticalSamplingFactor => 1))
ColorSpace => 1
color_type => YCbCr
ComponentsConfiguration => YCbCr
CompressedBitsPerPixel => 2/1
CustomRendered => Normal process
DateTime => 2003:08:02 12:17:27
DateTimeDigitized => 2003:08:02 12:17:27
DateTimeOriginal => 2003:08:02 12:17:27
ExifImageLength => 1200
ExifImageWidth => 1600
ExifVersion => 0220
ExposureBiasValue => 0/10
ExposureMode => Auto exposure
ExposureProgram => Program
ExposureTime => 10/500
filename => BrokenWindow.jpg
FileSource => (DSC) Digital Still Camera
file_ext => jpg
file_media_type => image/jpeg
Flash => Flash fired, compulsory flash mode, red-eye reduction mode, return light detected
FlashPixVersion => 0100
FNumber => 38/10
FocalLength => 63/10
height => 320
ImageDescription =>
InteroperabilityIndex => R98
InteroperabilityVersion => 0100
ISOSpeedRatings => 400
JFIF_Version => 1.01
JPEG_Type => Baseline
LightSource => unknown
Make => SONY
MakerNote =>
MaxApertureValue => 62/16
MeteringMode => Spot
Model => CYBERSHOT
Orientation => top_left
resolution => (72 dpi, 72 dpi)
SamplesPerPixel => 3
SceneCaptureType => Standard
SceneType => Directly Photographed Image
WhiteBalance => Auto white balance
width => 240
YCbCrPositioning => 2

Example 2: Listing select EXIF fields - Width, height, and date picture was taken (formatted)

Template code:

<MTImageInfo img="[MTBlogSitePath]/images/BrokenWindow.jpg">
  Width: <$MTImageInfoField name="width"$><br />
  Height: <$MTImageInfoField name="height"$><br />
  Date: <$MTImageInfoField name="DateTime" format="%a %d %b %Y"$><br />
</MTImageInfo>

Sample output:

Width: 240
Height: 320
Date: Sat 02 Aug 2003

Example 3: Listing select EXIF fields - Suppressing empty / non-existent EXIF fields

Template code:

<ul>
<MTImageInfo img="[MTBlogSitePath]/images/BrokenWindow.jpg"
    leading_text="[li]" trailing_text="[/li]">
  <$MTImageInfoField name="width" label="[strong]Width:[/strong]"$>
  <$MTImageInfoField name="height" label="[strong]Height:[/strong]"$>
  <$MTImageInfoField name="CoolBits" label="[strong]Cool Bits:[/strong]"$>
  <$MTImageInfoField name="DateTime" label="[strong]Date:[/strong]"
    format="%a %d %b %Y"$><br />
</MTImageInfo>
</ul>

Sample output:

  • Width: 240
  • Height: 320
  • Date: Sat 02 Aug 2003

Note on graphic editors

Some graphic editors (such as IrfanView) will preserve digital camera EXIF data when a picture is resized and saved, while other graphic editors (such as Adobe Photoshop CS) basically erase all digital camera EXIF data when a picture is resized and saved. If your images do not contain the EXIF fields that you think they should, you might try resizing your original digital camera pictures with a different graphic editor.

Credits

Lisa: Her MT Forum question inspired this plugin, plus she endured lots of questions from me during development and graciously tested plugin code on her weblog.

The 'build_value' sub was written by Kevin Shay and is used with permission.

The 'recursive_deref' sub is copyright (C) 2002 by Dan Harkless and released under the GNU General Public License.

Changelog

04/03/2004 - Initial public release (v1.0).

04/01/2004 - Version 0.22

  • "leading_text" argument added to MTImageInfo tag
  • "trailing_text" argument added to MTImageInfo tag
  • "label" argument added to MTImageInfoField tag
  • Allow html tags to be used in "leading_text", "trailing_text", and "label" arguments by using "[ ]" in place of "< >".
  • "show_empty" argument added to MTImageInfo tag
  • "ducky" code removed from plugin - testing revealed that editing otherwise normal digital camera pictures with Adobe Photoshop CS caused EXIF data to be moved into the special binary field.

03/28/2004 - Version 0.21

  • Display EXIF date/time fields in default MT blog date/time format.
  • "format" argument added to MTImageInfoField tag to format EXIF date/time fields.
  • Binary fields display size in bytes in addition to "(binary field)" text.
  • "filename" added as EXIF field that can be output with MTImageInfoField tag.
  • Invocation of Image::Info and File::Basename changed so MT does not initialize them every time MT runs except when called by tag during a rebuild.

03/28/2004 - Version 0.20

  • Added "ducky" code to read EXIF data encoded in special binary field ("App12-Ducky").

03/26/2004 - Version 0.11

  • Corrected HASH errors when non-existent EXIF fields were specified.
  • MT tags can be used to specify path/filename in MTImageInfo "img" argument.
  • Arrays and hashes are output as data instead of variable address reference.
  • Binary EXIF fields output string "(binary data)".

03/25/2004 - Version 0.10

  • 1st test version of plugin.

Leave a comment