#!/usr/bin/env python
"""Make a thumbnail for each file listed at the command line.

Usage:

    mkthumb file1 file2 ...

Simply calls ImageMagick's convert with a fixed width (250px).
"""

from __future__ import print_function

import os
import sys

# Width of the thumbnails, hardcoded for now
width = 250
# Set of formats we'll try to deal with, skip anything else
known = set(['.jpg','.jpeg','.png'])

# Main loop
files = sys.argv[1:]
if not files:
    print(__doc__, file=sys.stderr, end='')
    sys.exit(1)
    
for fname in files:
    # Only work on known image formats
    root, ext = os.path.splitext(fname)
    if ext.lower() not in known:
        print("Skipping file of unknown type:", fname)
        continue

    new_name = root+'_thumb'+ext
    cmd = 'convert -resize %sx %s %s' % (width, fname, new_name)
    print("Resizing:", fname)
    os.system(cmd)
