#!/usr/bin/env python #(c) May 2002 Thomas Guettler http://www.thomas-guettler.de #This Script is in the public domain #Feedback welcome # #This script creates a pdf file with pdflatex #for creating a memory-game. #Put the images with extension .jpg in a directory called images #For each image create .txt file (foo.jpg --> foo.txt) containing #a short description. #The script creates a memory-card for each image. #Print it twice, cut the cards, stick them on thick paper. #A nice present for you grandmother #The text for images in portait format need to start with "x" import os import os.path import re file=open('cards.tex', 'w') file.write( r"""%pdf-tex: \documentclass[a4paper,11pt]{article} \usepackage{ngerman} \usepackage[pdftex]{graphicx} % erlaube üöäßÜÖÄ im tex-file \usepackage[latin1]{inputenc} \pagestyle{empty} % keine Seitenzahlen anzeigen \begin{document} \noindent """) for img_filename in os.listdir('images'): text_filename=re.sub(r'(.*)\.jpg', r'\1', img_filename) if text_filename==img_filename: continue img_text=open('images/' + text_filename + ".txt") text=img_text.read() img_text.close() if text[0]=="x": #Ugly workaround: Text of images in portait format #should start with "x" width_or_height="height=4.8cm" text=text[1:] else: width_or_height="width=5.5cm" file.write(r"""\fbox{ \centering{ \parbox[c][6cm]{6cm}{ \centering{ \includegraphics[%s]{%s} \noindent %s } } } } \hspace{.5cm} \vspace{.5cm} """ % (width_or_height, 'images/' + img_filename, text)) print "wrote", text file.write("\end{document}\n") file.close()