Home

Login

Fotografía

Dreamstime

Shutterstock

Fotografía

Inf. Personal

Contact

Tutorials

Images Metadata

This tutorial shows how to build up a simple bash script to fill several Exif or IPTC tags in image files. This is of particular interest when filling the fields of 'Keywords', 'Title' and 'Description' of images to be submited to microstocking agencies such as Shutterstock, Dreamstime or Fotolia. You can make money with your photos! it is free and easy.

How does the script work?

The main idea reads as follows:
  • Get the name of all the image files
  • Create associated files where you can write all the information you want to write to the tags
  • Once the information has been written into the files, save it to the image file

    You should read and understand the code and change it accordingly to you needs. This code is provided with no warranty and no responsibility from the author.

    Step 1: Getting started

  • Any suggestion or commentaries regarding the script can be sent to locamfe-foto@yahoo.com.mx
  • The following script was made using bash on Ubuntu 10.04.
  • You need Exif 0.6.17 and EXIFTOOL (sudo apt-get install exif libimage-exiftool-perl libiptcdata-bin).
  • Note that the code can be simplified, but the elegance has been scarified for shake of understandability

    Step 2: Getting the name of all the relevant files

    First we need a script which gets all the files of the present working directory (pwd). This file will be called ObtenerArchivos.sh. Its output is a file called Resultado.nombres
    #!/bin/bash
    #Remove files from previous unfinished processes
    if [ -f *.teje ]
    then
    rm *.teje
    fi

    if [ -f *.nombres ]
    then
    rm *.nombres
    fi

    #Get the list of files and remove the first line
    ls -l | sed '1d' > Paso.teje

    #Gets only the files
    sed -n '/^-.*/p' Paso.teje | sed 's/.*teje//g' > Paso2.teje

    #Gets only the file names WITHOUT space
    sed -n 's/^.*[[:space:]]//gp' Paso2.teje > Resultado.nombres
    rm *.teje

    Now we can use the previous script to filter out the JPEG files, as shown below. The forthcoming script will be called ObtenerArchivosJPG.sh and its output will be the file ResultadoJPG.nombres

    #!/bin/bash

    #If there exist a previous file *.nombres, it will be removed
    if [ -f *.nombres ]
    then
    rm *.nombres
    fi

    bash ObtenerArchivos.sh
    #Get the files with extention [Jj][Pp]*[Gg]
    sed -n '/^.*[Jj][Pp][Gg]$/p' Resultado.nombres > ResultadoJPG.nombres
    sed -n '/^.*[Jj][Pp][Ee][Gg]$/p' Resultado.nombres >> ResultadoJPG.nombres

    rm Resultado.*

    Step 3: Create the associated files

    The next step is to create some files, in which the information to be recorded in the Keywords, Description and Title tags. This script will be saved in the file CrearDeArchivo.sh and produces no output.

    #!/bin/bash

    bash ObtenerArchivosJPG.sh

    #Verifies the 'Output' directory
    if [ ! -d Output ]
    then
    mkdir Output
    fi

    while read line
    do
    echo "${line}"
    touch "./Output/${line}.keywords"
    touch "./Output/${line}.title"
    touch "./Output/${line}.description"
    done < "./ResultadoJPG.nombres"

    After running this script, some files in the directory './Output/' will be created. In this files the keywords, description and title should be saved.

    Step 4: Save the information to each file

    Now we want to save the information of the files created in './Output/' to the appropriate file. This script will be saved in LlenarCampos.sh

    #!/bin/bash
    clear

    while read nombre
    do
    echo "${nombre}"
    etiquetas=$(sed -n '/^.*/p' "./Output/${nombre}.keywords")
    titulo=$(sed -n '/^.*/p' "./Output/${nombre}.title")
    descripcion=$(sed -n '/^.*/p' "./Output/${nombre}.description")
    exiftool -keywords="${etiquetas}" -headline="${titulo}" -title="${titulo}" -description="${descripcion}" "${nombre}"
    echo '######################################################'
    done < "./ResultadoJPG.nombres"

    Now the information have been recorded to the image file. It is very important to note that the information in the fields of 'Keywords', 'Title', 'Description', the image may have WILL BE ERASED AND REPLACED by the contents of the files in './Output/'. This captions are recognized automatically when uploading your photos to microstocking agencies such as Shutterstock, Dreamstime or Fotolia. This simplifies the work indeed!

    Should you have any suggestion or commentary, please send it to locamfe-foto@yahoo.com.mx

  • 54.162.241.40 : 44869