I've learned. I'll share.

February 1, 2008

The Easy Way to Print Flash Cards (with Python and ImageMagick)

Here's a valued lessons that I learned the long and hard way: how to easily print flash cards. Don't waste any time doing it the hard way like I did. Follow my easy route and save yourself some time.

The other day, my wife had a very simple computer need: print and cut pictures into little uniform cards, like flash cards with pictures. It sounds like a simple problem, but there's a simple way and an easy way, and I'd like to share with you the easy way.

The simple way is what she did: use some software like Scribus (in her case) or Microsoft Word (if she were almost anyone else), copy the pictures in, manually align them, and print. That works great ... until you try and do 700 pictures (about 80 pages of 9 pictures per page). Scribus ate all of the computer's memory, the hard drive thrashed like mad, everything slowed down, and my poor wife spent hours putting it all together. I doubt Word would have fared much better.

But it still wasn't over. When she tried to print, the printer printed out one page with "error" on it. So, we exported to a PDF, and tried printing that: "error" again. So, we tried to print one page at a time: after about 5 minutes, it printed. All I could figure was that something bad was going on between the computer and the printer and involving sending these images uncompressed.

At this point, I decided that it was time to call it quits on manual work and use automated work: write a program to do this for me. I'm not about to manually tell 78 pages to individually print. So, with some quick bash command line work, I told it to print each page by itself. That worked for a few pages, but some were still too big and we got the dreaded "error".

Finally, I decdied to really role up my sleeves and write a program like we should have in the first place: in go pictures, out comes a PDF, and your print the PDF. Additionally, I wanted like to control the DPI of the images used to control the data flow to the printer. I did so, made the PDF, printed it and (after a while, still), it printed. Hurray! Even better, now if we wanted to change pictures or change sizes, we'll be able to do it with very little work.

So here's the program. Put some pictures in a directory, run the program, and print the pdf of "flash cards" or "image thumbnails" or "reading lessons" or whatever you want to call them. You could even make this into an Automator task in Mac OS X. It uses ImageMagick, though, so make sure you have that installed first.

from subprocess import call

MONTAGE = ["montage", "-bordercolor", "white"]
CONVERT = ["convert", "-bordercolor", "white"]

def montage_files_of_paths(paths, name,
                           columns =  3, rows    = 3,
                           width   = 10, height  = 8, xborder = .33, yborder = .33, density = 200,
                           frame   = 5,  spacing = 10,                                            
                           intermediate_ext = "png", final_ext = "pdf"):

    width, height, xborder, yborder = (int(val * density) for val in (width, height, xborder, yborder))
    thumbnail_width  = int((width  - (xborder * 2)) / columns)
    thumbnail_height = int((height - (yborder * 2)) / rows)  

    call(MONTAGE + ["-tile",     "%rx%r" % (rows, columns),
                    "-geometry", "%rx%r+%r+%r" % (thumbnail_width, thumbnail_height, spacing, spacing),
                    "-frame",    str(frame),
                    "-density",  str(density)]
                 + [path + "[0]" for path in paths] #[0] to ignore animated GIFS
                 + [name + "." + intermediate_ext])
    call(CONVERT + ["-border",   "%rx%r" % (xborder, yborder),
                    "-density",  str(density),
                    "-annotate", "0x0+%r+%r" % (xborder, yborder), name,
                    name + "*." + intermediate_ext,
                    name + "."  + final_ext])

import sys

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print "usage: %s image_directory, image_directory, image_directory ..." % (sys.argv[0],)
        for dirname in sys.argv[1:]:
            montage_files_of_paths([dirname+"/*"], dirname)


  1. The positive parts of gas golf trucks is that they have more power than their electric partners and along these lines, improve if the green you ordinarily golf has a scene with loads of slopes.cheap post card printing cheap55printing.com

  2. To buy essay online you better use some trusted services. Like this one

  3. Meeting your prospective client can be a daunting task. What slides do you present? What ideas do you push? What are their needs you should focus on? It is a difficult task. check out Advantages of Physical Print

  4. Thanks for sharing this beautiful post for the spring of watercolors. use in a different manners is really awesome. Urdu Novels

  5. Thanks for this informative article hope so comment is also informative in case of using the quickbooks for accounting software for accounts thus it has the sometime issue arise which is problem in opening of the company file due to communication server error which can be resolved by the quickbooks diagnostic connection tool

  6. Thanks for sharing this informative content.,
    Leanpitch provides online training in Scrum Master Certification during this lockdown period everyone can use it wisely.
    Join Leanpitch 2 Days CSM Certification Workshop in different cities.

    Scrum master certification online

    CSM certification online

    CSM online

    CSM online certification

    CSM online training

    CSM training online

    Scrum master training online

  7. Thank you so much for showing us such an easy way of doing to print these flash card. You seem like a very all-rounded and knowledgeable person. can you please can you post an article on where to get your dissertation written for you, I have been looking for an authentic service for a while now. If you can suggest a few I will be thankful. Keep us posted, please!

  8. Wow, Python never fails to surprise me. My husband who works in a Presentation writing service UK first introduced me to python and soon enough I got obsessed with this language. Every day learning more about it only adds to my obsession. Thank you so much for writing this post for us. Keep posting!

  9. I have been browsing online more than 3 hours today, yet I never found any interesting article like yours. It's pretty worth enough for me. In my view, if all site owners and bloggers made good content as you did, the net will be a lot more useful than ever before 토토

  10. Just desire to say your article is as surprising. The clearness on your publish is
    simply spectacular and that i can assume you're knowledgeable on this subject. 경마

  11. 온라인카지노 I all the time used to read article in news papers but now as I am a user of web therefore from now I am using net for articles or
    reviews, thanks to web.

  12. 온라인카지노사이트 Pretty! This was an extremely wonderful article. Thanks for
    supplying this info.

  13. What’s up it’s me, I am also visiting this website
    regularly, this web page is really good and the users
    are in fact sharing nice thoughts. 토토

  14. 스포츠토토 Think about the sorts of items you use a lot of in a two-week period. Paper goods are probably at the top of this list, including things

  15. I love it here. Keep sharing your good vibes. I love them Are you also searching for dissertation writing help? we are the best solution for you. We are best known for delivering cheap assignments to students without having to break the bank

  16. I love it here. Keep sharing your good vibes. I love them Are you also searching for Online mathematics help? we are the best solution for you. We are best known for delivering cheap assignments to students without having to break the bank

  17. Thank you for explaining how to easily print flashcards in your post, I have understood all the algorithms well, and now I will be able to print flashcards on my computer in a custom way. But there is a question: Can I change the code and set it to auto? Dissertation Editing Service

  18. This comment has been removed by the author.

  19. This comment has been removed by the author.

  20. This is the easy way to print easily flash cards.Last week,my friend want to cut and print some pictures from her computer to a uniform card.He did't find any way.I visit your blog and get amazed by your reviews.I will tell her about your blog and say to visit it after completing some projects at my firm Cheap Dissertation Writing Services UK

  21. I really appreciate the information that you have shared on your post, tjc discount code Thanks for shearing this post.

  22. Representing annual duties can be trying as organizations explore the quickly changing worldwide duty climate tax consultant, changing business conditions and expanded requests for straightforwardness. PwC's.

  23. Farenflights is best the international travel agency delhi which helps you book a vacation; We want to be your travel partner who will go the extra mile to help you choose the perfect destination and learn more about the place you’ve been dreaming of visiting. Since vacations are all about personal choices and interests, we also offer you customizable tour packages. We give you the right to pick and choose anything that matches your interests. No matter how many travel experiences we sell each day, we guarantee that you’re the hero of your travel story.

  24. اذا كنت تبحث عن احسن دكتور اوعية دموية في مصر ف لن تجد افضل من الدكتور محمود ناصر حيث انه يقوم ب علاج الدوالي بدون الم او جراحة باستخدام احدث التقنيات لاجراء العملية بدون جراحه فيقوم ب علاج الدوالي بتبريد الجلد واستعمال حقن الدوالي والليزر معاً في تقنية تسمي الكلاكس، حيث انها من احدث التقنيات الحديثه لعلاج دوالي الساقين بدون الم

  25. Such an excellent blog. The topic of this post is very interesting for me. I am very much impressed after reading this post. I must appreciate your effort in sharing this post with us here. Now it's time to avail HALFCASTE CREAM SET for more information.

  26. Your post is very helpful and your information is reliable. I am satisfied with your position.
    Traffic Lawyer Orange VA is a legal service provider located in Orange, Virginia that specializes in representing clients who have been charged with traffic violations. Their team of experienced traffic

  27. The website valuedlessons.com offers a fantastic resource for those seeking an easy and efficient way to print flashcards. The article, titled "Easy Way to Print Flash Cards," provides clear instructions and practical tips for creating flashcards that can be used for studying, teaching, or even playing educational games. This resource is incredibly valuable, especially for students, teachers, and parents looking for a cost-effective and customizable way to enhance learning.Cheap Dissertation Writing Services UK

  28. Printing flashcards can be a tedious task, but your journey from manual work to creating an efficient automated solution is a valuable lesson in optimizing productivity. Your provided program is a great resource for simplifying the process. Thanks for sharing your experience and solution! Abogados de Divorcio en Glens Falls Nueva York Abogados de Divorcio en Manhattan Nueva York

  29. Thank you for sharing such a wonderful article.

  30. I would like to be here again. Thank you!

  31. Thanks for the information your article brings.

  32. I got really good information from this content, thanks for sharing.

  33. Thanks for sharing this lifesaver! Printing flash cards can be a headache, but your Python and ImageMagick solution is a game-changer. A valuable lesson indeed—time saved is truly time gained!
    New York Divorce Law No Fault

  34. thanks for sharing.Thanks for taking the time to post such valuable information.
    divorcio de nueva jersey


Blog Archive

Google Analytics