SPIP-Contrib

SPIP-Contrib

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

251 Plugins, 182 contribs On SPIP-Zone, 70 visitors now

Home page > 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

[1] A 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.

[2] the name and number of fields being variable

[3] cvs version of 17 Dec. 2004

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

Back to top

Reply to this article

Who are you? (optional)
  • [Sign In]

Pour afficher votre trombine avec votre message, enregistrez-la d'abord sur gravatar.com (gratuit et indolore) et n'oubliez pas d'indiquer votre adresse e-mail ici.

Ajoutez votre commentaire ici
  • Ce formulaire accepte les raccourcis SPIP et le code HTML. Pour créer des paragraphes, laissez simplement des lignes vides.

Add a document

Back to top

Here they're talking

  • (fr) Inscription 2

    4 juin 2007 – 414 commentaires

    Ce "plugin" permet de configurer un formulaire d’inscription personnalisable pour les visiteurs d’un site Web, ainsi qu’une table auteur étendue associée, ce de manière générique (réutilisable par d’autres plugins)... ! Le paquet zip disponible n’est (...)

  • (fr) Le plugin FreepapeR 2 v0.9.0

    10 mars – commentaires

    Un outil pour visualiser en ligne les fichiers PDF. Cette nouvelle version intègre une présentation "Livre". L’outil est installé sur son propre serveur, pour des documents toujours disponibles et jamais altérés... Il n’y a aucune dépendance envers (...)

  • (fr) plugin Forms : création de formulaires

    25 octobre 2006 – 657 commentaires

    Documentation basique du plugin Forms pour son volet création de formulaires.

  • (fr) Plugin Gis escoitar

    15 avril 2007 – 587 commentaires

    Plugin pour l’intégration de Google Maps dans SPIP

  • (fr) Utiliser et personnaliser le formulaire public d’ajout d’articles

    20 octobre 2009 – commentaires

    La procédure sous SPIP 2 pour mettre en place la proposition publique d’articles Le projet pour lequel j’ai travaillé cette procédure est un dictionnaire de traduction. il y a donc la procédure pour la proposition publique d’articles et une partie (...)