n: smd_meta_image | v: 0.5.1 | f: /

Documentation for the Textpattern plugin smd_meta_image by Stef Dawson follows this short message from our sponsor ;-)

Plugin list button Plugin download button Compressed plugin download button

smd_meta_image

Upload images and populate their metadata from IPTC header information. Very handy for people who run photoblog or image-heavy sites, or those who categorise images for inclusion in articles. If configured, the plugin will automatically create an article for each uploaded image.

Features

  • Map image IPTC fields to Textpattern image/article fields.
  • Articles may be created automatically based on embedded IPTC data.
  • Article/image categories may be created automatically if required.
  • Upload/replace images to update Textpattern metadata.

Installation / Uninstallation

Requires Textpattern 4.7+

Download the plugin, paste the code into the Textpattern Admin->Plugins panel, install and enable the plugin. For bug reports, please raise an issue.

To uninstall, delete the plugin from the Admin->Plugins panel.

Configuration

Visit the Admin->Prefs panel and click the Meta Image Import group to configure the plugin. There are three sections as follows:

General options

Article parent category

The parent category in your current article tree where all new categories read in from the IPTC data will be created. If set to Disable category creation then no categories will be created and assignment will only occur for those categories that already exist. If set to the empty (blank) option, new categories will be created at the root (top level).

Section

The Section in which articles will be created. If left blank, the Default Section (as defined in the Sections panel) will be used.

Image mapping

One configuration item per Textpattern image field. Select an IPTC field from the list for each Textpattern field so that it may be mapped when images are uploaded.

Leave any select list blank to indicate this field should be ignored – i.e. have its data set to whatever Textpattern usually assigns on image upload.

If you leave the Name field blank, or the nominated IPTC field in the image is empty, Textpattern will use the filename as usual.

Article mapping

As above, there is one configuration item per Textpattern article field. Select an IPTC field from the list for each Textpattern field so that it may be mapped when images are uploaded. Any fields you specify here will result in one article being created for every image.

There are some special cases as follows:

Title

This is the key field that ties your image to your article. If you don’t map this field (i.e. set it blank) then no article will be created when you upload an image. This is handy as a “turn off article creation” switch that leaves all other fields intact, or for people who just want to map image data on import, and not create articles.

Once set, it’s a good idea not to alter it. If you do, the article won’t be “found” again if you subsequently replace an existing image.

Article image

This is set to the image ID of the uploaded image.

Section

This is only set on article creation, not altered when an image is replaced.

If the Section is set in the plugin’s general options, the nominated Section will be used when creating articles from each uploaded image. If the Section is left empty in the plugin’s general options, the current Default Publishing Section (as defined on the Sections panel) will be used when creating articles.

Status

The value from your ‘Default publication status’ pref is used. The status is only set when images are first uploaded. It is not updated when replacing images.

Keywords

These are concatenated as a comma-separated list and updated when an image is replaced. The list will be truncated if they don’t fit in the 255 char limit.

Posted date

If assigned from the image Creation Date IPTC field, it behaves as follows:

  1. It automatically adds the Creation Time IPTC field as well, to form a full date-time value.
  2. It is only assigned at article creation time. If the image is replaced, the article posted date remains the same.
  3. If the field cannot be read or is mangled then the upload date/time is used (a.k.a. ‘now’).
  4. If the Posted date is not mapped, then the upload date/time is used as article creation datestamp.

Author/LastMod info

This is always set on insert and update of its corresponding image. The current logged-in user is used, and the article’s modification date is set to ‘now’.

Category assignment

Categories are treated differently depending on where (to which field) they are assigned. IPTC category fields are:

  • (2#012) Subject Reference
  • (2#015) Category
  • (2#020) Subcategory

They will be treated like regular fields if they are assigned to any non-Category Textpattern field (e.g. custom fields). In these cases, single category values will be inserted as regular fields and category lists will be inserted as a comma-separated list.

If, however, you assign one of the category fields to a Textpattern Category field, it behaves like this:

Image categories

  • If the category (or first category if the nominated IPTC field represents a list) does not exist, it will be created as an image category.
  • If you have specified an existing Textpattern category in the Upload form, that will be used as the parent of any created categories.
  • If any category already exists, no changes will be made to it.
  • If the nominated IPTC field is empty, the category used in the upload form will be assigned to the image as fallback.
  • If that’s empty, no category will be assigned to the image.

Article categories

  • If the category (or first category if the nominated IPTC field represents a list) does not exist, it will be created as an article category as long as the parent category is not set to Disable category creation.
  • New categories read from image data will be created beneath the parent category set in the plugin’s general options. If the parent category is unset, new categories are assigned to the article root.
  • If a category already exists, its definition and parent remain the same – no changes are made, only category (re)assignment to the article is performed.

Custom values

If you wish to combine field data or make your own content to be inserted into a field, choose the last Custom value option from the configuration item list for any corresponding Textpattern field. A new input box will appear below the selector for you to type in the text you wish to be inserted into that field.

If you wish to insert a particular field code within your custom text, specify its name in curly braces. For example: {2#004} is Genre, {2#090} is City and {2#105} is Headline. See Section 6 of the IPTC Spec and look at the IIM Spec values to get the codes. Simply pad the values to the right of the colon with zeroes to three digits and replace the colon with a hash (#) sign. So, for example, ‘Creator’ has an IIM Spec designator 2:80. To import this value into your nominated field, use {2#080}.

If you’re unsure of the values, either a) inspect the browser page source code of the prefs panel and look at the values in one of the configuration item select lists, or b) check the plugin code – there’s a function called getIptcMap() which lists the main supported data fields and their values.

For lists of values that are treated as arrays (Subcategories, Subject Reference, Keywords and Author Byline) it’s possible to use custom values to extract individual entries instead of the entire set as a comma-separated list. To do this, append a colon and offset to the field code. For example, to extract just the third subcategory value, specify:

{2#020:3}

Or the 6th Keyword:

{2#025:6}

Note:

  • If the contents of the field at the given offset value is missing (e.g. no value, or set to 0), you will get the entire field comma separated as if you hadn’t used the offset. This allows you to manually edit the result later to remove the parts you don’t want.
  • A single space character in the field is not treated as “empty” so if you wish to skip the entry and have your Textpattern destination field appear blank, specify a single space in the image metadata.

Usage

  1. Visit the Images panel.
  2. Browse/drag one or more images to the upload field.
  3. Optionally select a category for it (or under which its new categories will be created).
  4. Ensure the Parse IPTC data checkbox is set.
  5. Upload the images.

Images will be uploaded, and have their metadata set according to the mapping rules set in the plugin preferences. If article mapping is configured, one article will be created per image too with the nominated data copied from the corresponding image’s IPTC field into the article.

Caveats / known issues / other stuff

  • The custom field names in the Prefs panel are not translated and do not read the values for their names as defined in the CF prefs.
  • The ‘Parse IPTC’ checkbox is remembered after you have performed an upload. The same state is applied for new uploads and for replacements – it uses the same pref value.
  • The plugin plays nicely with smd_thumbnail.
  • Only a loose link between the image and its article is enforced after creation. If the Title remains unchanged and the Title mapping field is unchanged, updating an image will update the corresponding article data (with the exceptions noted above). But if you delete an image or delete an article, they are treated independently.

Source code

If you’d rather wander aimlessly through thousands of lines of PHP source code, you’ll need to step into the view source page.

Legacy software

If, for some inexplicable reason, you need an old version of a plugin, it can probably be found on the plugin archive page.

Experimental software

If you’re feeling brave, or fancy skateboarding into volcanos, you can test out some of my beta code. It can be found on the plugin beta page.