#!/usr/bin/python # usage: image_to_dcf.py myimage.png # minimal program to write any image in a form that is suitable for # viewing on a cybershot -- proof of concept only, no warranty ... # ewan_at_mathcode_dot_net # This python program is based originally the comments above. # Version 2 - Chieh Cheng # Changes from version 1: # 1. check for valid input file name # 2. allow arbitrary number of files on the command-line # 3. add usage text import Image import os import sys def usage (): print ' Usage: DCF.py "image 1" [ . . . "image n" ]' def padZeros (num): result = "" if num < 1000: result = result + "0" if num < 100: result = result + "0" if num < 10: result = result + "0" result = result + str (num) return result def getUniqueName (): count = 1 name = 'DCF_' + padZeros (count) + '.JPG' while os.path.isfile (name): count = count + 1; name = 'DCF_' + padZeros (count) + '.JPG' return name argc = len (sys.argv) for i in range (1, argc): filename = sys.argv [i] if os.path.isfile (filename): im = Image.open(filename) oim = im.copy() oim = im.convert('YCbCr') oim.mode = 'YCbCr' outfile = getUniqueName () oim.save(outfile, 'JPEG', quality=100) else: print filename, "does not exist!" if argc == 1: usage ()