|
|
A Python script to organize digital photos
For what it's worth, here's my version, which I've been using for some time, on Linux, then Windows, and now on my Mac, where I run it using an AppleScript menu item after Image Capture has put my photos in my Pictures directory.
This creates one directory per month and names the images within those based on their creation time, eg:
#!/usr/bin/python
# Copy image files from a source into a photo directory.
# Name them according to their date of creation.
# Put them in a directory based on the month.
import sys, os, glob, time, string
def copyfiles(srcdir, destdir, pattern, move=0):
srcfiles = glob.glob(os.path.join(srcdir, pattern))
for i in srcfiles:
ext = os.path.splitext(i)[1]
t = time.gmtime(os.path.getmtime(i))
newname = time.strftime("%Y_%m_%d-%H_%M_%S",t) + ext
monthdir = os.path.join(destdir, newname[:7])
if not os.path.isdir(monthdir):
print "Creating new dir", monthdir
os.mkdir(monthdir)
fullnewname = string.lower(os.path.join(monthdir,newname))
# if file already exists, we add a suffix
testname = fullnewname
suffnum = 1
while os.path.exists(testname):
testname = "%s.%02d" % (fullnewname, suffnum)
suffnum += 1
if testname != fullnewname:
fullnewname = testname
print i,"->",fullnewname
if move:
os.rename(i, fullnewname)
else:
s = open(i,"rb")
d = open(fullnewname, "wb")
while 1:
b = s.read()
if not b: break
d.write(b)
d.close()
s.close()
def main():
srcdir = "/Users/qsf/Pictures"
destdir = "/Users/qsf/Pictures"
if len(sys.argv) > 1:
srcdir = sys.argv[1]
if len(sys.argv) > 2:
destdir = sys.argv[2]
copyfiles(srcdir, destdir, "*.jpg*", move=1)
copyfiles(srcdir, destdir, "*.JPG*", move=1)
if __name__ == "__main__":
main()
A Python script to organize digital photos
I have trouble remembering what happened during this or that month, so I found that keeping all photos in one directory is better for me. Usually I organize a new directory when I have enough photos for a CD.
One more alternative - jhead
I use a program called jhead to rename my photos. It's written in C, so it's very fast...the link above has a pre-compiled OS X binary, but I built it from source with no problems. The nice thing about this program is that it extracts image info from the EXIF header, so it's completely independent of the file's creation or modification time. Furthermore, it can reset the modification time of the actual JPEG to match that given in the EXIF metadata (in case you've rotated the pic in Photoshop, for example). This one-liner renames an image in the form YYYY-MM-DD_hh-mm-ss, so that 'View by name' will list all files in chronological order, accurate to the second: jhead -nf%Y-%m-%d_%H-%M-%S [files...]
Now cataloging those lurching, blurred, drunken mugshots is a breeze.
One more alternative - jhead
This is a great idea to use exif data for the date. |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.07 seconds |
|