Skip to content

Instantly share code, notes, and snippets.

@fubits1
Created April 11, 2022 13:51
Show Gist options
  • Save fubits1/7033893029c2b0e07f402238bc5e1904 to your computer and use it in GitHub Desktop.
Save fubits1/7033893029c2b0e07f402238bc5e1904 to your computer and use it in GitHub Desktop.
Mass-add metadata to JPGs / annotate with alternative descriptions, copyright etc
#!/bin/bash
## libraries: sed, exiftool
# sudo apt-get install sed libimage-exiftool-perl
## if output folder is needed
# [ -d output-folder ] || mkdir output-folder # checks if output folder exists, and create if not
i=0 # to track iteration cycle for lookup by row in text file with sed
## for each JPG
for filename in source-folder/*.jpg; do
((i++))
## lookup row i in text file
desc="$(echo "$output" | sed "${i}q;d" alt.txt)" # capture sed output in ${desc}
# echo "${desc}"
[ -e "$filename" ] || continue # escape if no file
# echo "${i} - ${filename%.*} - ${desc}" # ${filename%.*} prints filename without extension
exiftool -mwg:copyright="CC-BY-SA 4.0" -mwg:keywords="Keyword1; Keyword2;" -mwg:description="${desc}" -xmp:title="Title" -iptc:ObjectName="Title" -mwg:creator="Author / Owner" -overwr
@fubits1
Copy link
Author

fubits1 commented Apr 11, 2022

Task Description

mass-annotate a folder of JPG image files with alternative descriptions, license etc. from a text-file

Approach

  • iterate over set (folder) of JPG files
  • for each file
    • track current iteration number in var ${i}
    • extract description ${desc} from file alt.txt, in row ${i}
    • with exiftool add metadata (description, copyright, title, author)

Prerequisites

  • folder of JPG files
  • text file .txt with
    • 1 description for each image per line
    • in the same (!) order as the files

Need more Tags?

You can lookup the supported universal MWG tags as well as the specific metadata standards (i.e. Exif, IPTC, XMP) here

TODO

  • add workflow for PNGs (semi-straightforward support for Exif exists)
  • add workflow for splitting title and description from alt.txt (or simply work with two files)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment