1. msaelices
  2. python-resize

Commits

msaelices  committed f299b4b

Uploaded first version of the resizing script.

  • Participants
  • Branches default

Comments (0)

Files changed (1)

File src/resize.py

View file
+#!/usr/bin/env python
+
+import glob
+import Image
+from os import path
+from optparse import OptionParser
+
+
+def main():
+    parser = OptionParser()
+    parser.add_option("-d", "--directory", dest="directory", default='.',
+                      help="directory to make thumbnails")
+    parser.add_option("-s", "--size", dest="size", type="int",
+                      default=1024, help="extension to search")
+
+    (options, args) = parser.parse_args()
+
+    base_dir, size = (options.directory, options.size)
+    glob_expression = path.join(base_dir, '*')
+
+    for infile in glob.glob(glob_expression):
+        filename, filedir = path.basename(infile), path.dirname(infile)
+        print 'Doing thumbnail of %r to %dx%d...' % (filename, size, size)
+        try:
+            im = Image.open(infile)
+        except IOError:
+            print '%r does not seems to be an image file. Discarded.' % filename
+            continue
+        # don't save if thumbnail already exists
+        if filename[0:2] != "T_":
+            # convert to thumbnail image
+            im.thumbnail((size, size), Image.ANTIALIAS)
+            # prefix thumbnail file with T_
+            im.save(path.join(filedir, "T_" + path.basename(im.filename)), "JPEG")
+
+
+if __name__ == '__main__':
+    main()