Skip to content

Instantly share code, notes, and snippets.

@reinout
Created September 20, 2016 06:48
Show Gist options
  • Save reinout/958693f58de27846e0c5b8bc272fb89d to your computer and use it in GitHub Desktop.
Save reinout/958693f58de27846e0c5b8bc272fb89d to your computer and use it in GitHub Desktop.
Script to add descriptions underneath eifelbahn.de DVD photos
# -*- coding: utf-8 -*-
import codecs
import os
# Directory with the hi-res images from the DVD
SOURCE_DIR = '../hg-eqb1-a'
# Directory where you want to place the files '.' is the current dir.
TARGET_DIR = '.'
# Export the .rtf with the image descriptions as plain text. The output should
# look like this:
#
# Informationen zu den Fotos auf der CD-ROM Eifelquerbahn 1
# Bild
# Ort
# Beschreibung
# Datum
# hg-q-0001
# Ulmen
# 050 821-8 mit Güterzug von Daun nach Mayen im Bahnhof Ulmen, Mai 1970.
# 1970/05
# hg-q-0002Ürsfeld
# BR 798 mit Steuerwagen im Bahnhof Ürsfeld, Mai 1970.
# 1970/05
# hg-q-0003Ürsfeld
# 050 821-8 mit Güterzug im Bahnhof Ürsfeld, Mai 1970.
TEXT_FILE = '../eqb.txt'
# The 'convert' program is part of the imagemagick package.
CMD_LINE = ("convert {input_file} -pointsize 32 -background White "
"label:'{text}' -append {output_file}")
def main():
lines = codecs.open(TEXT_FILE).readlines()
image_number = None
for line in lines:
if line.startswith('hg-q-'):
# 'hg-q-0002Ürsfeld', adjust name if you have different files.
# Also adjust the index numbers below, then.
image_number = line[5:9]
continue
if image_number:
# Line after image number is the actual text
text = line.strip()
input_file = os.path.join(
SOURCE_DIR,
'hg-q-{image_number}-a.jpg'.format(image_number=image_number))
output_file = os.path.join(
TARGET_DIR,
'{image_number}.jpg'.format(image_number=image_number))
print("Converting %s into %s..." % (input_file, output_file))
os.system(CMD_LINE.format(input_file=input_file,
output_file=output_file,
text=text))
image_number = None
# ^^^ Reset until we have an image number line again.
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment