SPIP-Contrib

SPIP-Contrib

عربي | Deutsch | English | Español | français | italiano

273 Plugins, 191 contribs On SPIP-Zone, 39 visitors now

Homepage > Admin and maintenance solutions > Gestion des documents > Données Exif > #EXIF tag: get informations directly from the images.

#EXIF tag: get informations directly from the images.

11 July 2005 – by mortimer

All the versions of this article: [English] [Español] [français]

In place of the default tags provided by SPIP for documents, we are going to extract the data stored in the image files with the help of new tags for SPIP.

Goal

With the new compiler, there is now the possibility to create personalized tags.

The integration in SPIP of the jpg EXIF metadata could be done with this. The data stored in the jpg file can be the time the photo has been taken, a copyright or GPS data for example.

All the code presented in this article has to be copied at the end of your file mes_fonctions.php3.

PHP provides functions to access these data. We will then start to write a little wrapper to access them on SPIP documents:

-  The first function tests if a file can contains EXIF metadata (if it’s a TIFF or JPEG file).
-  The second one returns the field we are interested in. It is accessed with an argument giving the section where to look for it and another argument being the name of the field. These arguments are not mandatory and if not provided, a list of tag is returned [1].

The tag

A new tag #EXIF is declared. Here is a first simple version:

When this tag will be detected, the function balise_exif will be called without any parameters. Hence, it will return a list of all the fields available in the file.

We begin by getting the name of the file attached to the document. For that we need the ID of the document. This is done by the sugar-function champ_sql that is a shortcut to index_pile:

index_pile returns the position in the stack of the SQL field $nom_champ. Starting from the nearest loop (given by $idb). If nothing is found, the field is considered to come from the outmost context (the URL or include) that is found in $Pile[0]. If the name references a SQL field, then it is stored in the $boucle structure to construct the minimal SQL query.

champ_sql will use $param to find the nearest loop, the second parameter is the name of the field: 'id_document'

The code for this tag must be run during the construction of the cache. Hence, we return a string containing the code to run later: "(verifier_JPG_TIFF($id_doc))?(tag_exif(generer_url_document($id_doc))):''"

To distinguish between php and pure html, the type of code is also specified by: $params->type = 'php';

Adding parameters

Well, this new tag is not really useful as is. In fact, we would prefer to extract only the field that we are interested in. But we do not really want to create one tag per field [2]. To avoid that, we will user parameters passed to this tag to select the right field.

Since version 1.8 [3], SPIP provides a simple function to retrieve parameters passed to a tag. This function is used in the following code. For earlier method of retrieving parameters, as for #EXPOSER|on,off, see the logo part of the code explained below.

The same method will be used to add two parameters to the #EXIF tag. For example:#EXIF{FILE,FileName} and #EXIF{IFD0,DateTime} will respectively retrieve the file name field from the File section and the date and time field from the IFD0 section (date and time the photo has been taken).

Here is the new code:

The difference with the code returned by the previous version is small. However, the parameters $section and $tag are retrieved from the filter list (params->fonctions) to be passed (if found) to the function tag_exif.

A tag for a thumbnail

In the EXIF metadata from a jpg image, there is — often — a thumbnail of the image [4]. This thumbnail is not of the best quality, but when you are unable to install any image processing plugin in PHP it is a good start.

Lets begin with two new tool functions:
-  generer_url_logo_EXIF look for the file name_file.exif.jpg on the server. If this one is not find, the thumbnail is retrieved from the image and written to disk. The name of the thumbnail file is returned at the end.
-  generer_html_logo_EXIF create the html code for the thumbnail, with alignment, link, etc...

This new tag should have the same behavior as the other LOGO tags in SPIP. Therefor the alignment and link filters should be implemented properly.

The principle is the same as before. The list of filters is parsed for one of the following:
-  an alignment,
-  fichier to return the name of the file,
-  a link to put around the thumbnail.

The first part of the code looks at the filters in $p->fonctions. Then, the code for the link is generated if necessary. As another tag can be given as a link — e.g. [(#LOGO_EXIF|#URL_DOCUMENT)] — we call the function calculer_champ to compute the content of this tag.

A filter for the dates

The dates stored in the images are not in the same format as the one used by SPIP. Hence, it is not possible to use the filters on dates from SPIP. Here is a filter to apply before any date filter from SPIP:

Application example

Here is a little loop that list all the documents of an article with some basic informations extracted from the EXIF metatags:

Development version

This contrib is managed on spip-zone. You can checkout the last version with:

svn checkout svn://zone.spip.org/spip-zone/_contrib_/_balises_/exif/trunk/

Footnotes

[1A little cache in memory allow the system to read the data from the file only once when there is a consecutive access to the same image.

[2the name and number of fields being variable

[3cvs version of 17 Dec. 2004

[4This is generated by the camera for visualization on the camera screen, for example.

Back to top

Comment on this article

Who are you?
  • [Log in]

To show your avatar with your message, register it first on gravatar.com (free et painless) and don't forget to indicate your Email addresse here.

Enter your comment here Les choses à faire avant de poser une question (Prolégomènes aux rapports de bugs. )
Add a document

Back to top

Here they're talking

  • (fr) Typographie avancée

    3 mars 2010 – <blink style='color:red;'>public|spip|ecrire:commentaires</blink>

    « Typographie avancée » active automatiquement un grand nombre d’automatismes destinés à affiner la typographie des textes produits par SPIP. Nécessite PHP 5 au minimum. « Typographie avancée » est l’adaptation, pour SPIP, de la classe « PHP Typography », (...)

  • (fr) Plugin Convertisseur

    24 février 2008 – 15 <blink style='color:red;'>public|spip|ecrire:commentaires</blink>

    Convertit différents formats d’articles (wiki, docx, pdf, etc..). en format SPIP (texte avec les raccourcis typographiques SPIP)

  • (fr) Thèmes pour l’interface privée

    22 février 2010 – <blink style='color:red;'>public|spip|ecrire:commentaires</blink>

    Un sélecteur d’interfaces graphiques pour l’espace privé de SPIP 2.1. Une petite collection d’interfaces est livrée avec le plugin. Ce plugin permet à chaque participant à l’espace privé de sélectionner sa propre interface graphique en fonction de ses (...)

  • (fr) Albums

    8 novembre 2011 – 29 <blink style='color:red;'>public|spip|ecrire:commentaires</blink>

    Ce plugin permet d’afficher une ou plusieurs galeries d’images au fil du texte, dans les articles et ailleurs. Qui rédige un récit de voyage, par exemple, aimerait pouvoir illustrer son article de plusieurs petites séries de photos, une par jour. Or (...)

  • (fr) Navigation AJAX

    31 janvier – 17 <blink style='color:red;'>public|spip|ecrire:commentaires</blink>

    Ce plugin permet de modifier automatiquement une parties des liens internes de manière à ce qu’ils ne déclenchent pas un chargement complet de la page cible, mais un chargement en AJAX de certains éléments spécifiés à l’avance. Il permet aussi de (...)