#!/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 # Chieh Cheng # Version 1 # This python program is based originally the comments above. # I have made the following changes: # 1. Changed /usr/local/bin to /usr/bin # 2. Changed image_to_dcf.py to DCF.py # 3. Output file name as "DCF_xxxx.JPG", where xxxx is a unique number import Image import os import sys filename = sys.argv[1] # input isn't checked, # it is user's responsibility to make sure # that input filename has 3-letter extension eg .jpg or .png im = Image.open(filename) 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 outfile = getUniqueName () # after conversion, you'll want to rename the output file # to the format AAAANNNN.JPG, where 'AAAANNNN' has 8 characters, # A representing an uppercase letter, N a number form 0001 to 9999 oim = im.copy() oim = im.convert('YCbCr') oim.mode = 'YCbCr' oim.save(outfile, 'JPEG', quality=100)