Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit beba031f0b04a75914981d3eb783e1e3a0e62439 @oblique63 committed Mar 16, 2010
Showing with 457 additions and 0 deletions.
  1. +19 −0 img_resizer.py
  2. +1 −0 src/__init__.py
  3. +9 −0 src/download.py
  4. +106 −0 src/interface.py
  5. +52 −0 src/path_parser.py
  6. +249 −0 src/resizer.py
  7. +21 −0 src/uploader.py
@@ -0,0 +1,19 @@
+#! /usr/bin/python
+
+# Program: Image Resizer
+# Author: Enrique Gavidia
+# E-mail: enrique@enriquegavidia.com
+# License: TBD
+# Date: 2008-2010
+
+from src.resizer import Resizer
+from src.interface import display_interface
+
+imgResizer = Resizer()
+
+# If user gives no commandline arguments, display user interface
+if len(imgResizer.path_input()) < 1:
+ display_interface()
+else:
+ imgResizer.resize()
+
@@ -0,0 +1 @@
+
@@ -0,0 +1,9 @@
+from resizer import Resizer
+import urllib
+
+def download(url):
+ local_filename = url.split('/')[-1]
+ urllib.urlretrieve(url, local_filename)
+ resized_img = Resier(local_filename)
+ resized_img.resize()
+
@@ -0,0 +1,106 @@
+# Program: Image Resizer
+# Module Description: Command Line Interface
+# Author: Enrique Gavidia
+# E-mail: enrique@enriquegavidia.com
+# License: TBD
+# Date: 2008-2010
+
+from resizer import Resizer
+import os
+
+def __print_intro():
+ print "Image Resizer"
+ print "=" * 40
+
+def __print_menu():
+ print
+ print "Please enter your preferences for each of the Menu Options you would"
+ print "like to adjust, and enter '7' when you are done to execute your request."
+ print "(note: default values for options 2-6 will be used if none are given)"
+ print "-" * 40
+ print "[1] Image Source"
+ print "[2] Destination for resized file(s)"
+ print "[3] Resized file(s) suffix"
+ print "[4] Maximum file size"
+ print "[5] Image resolution"
+ print "[6] Upload Images -- Currently Unavailable"
+ print "[7] Resize!"
+ print "[8] Help"
+ print "[9] Exit"
+ print
+
+def __print_help():
+ print "HELP!"
+ raw_input()
+
+def __clear():
+ if os.sys.platform.startswith('win'):
+ os.system("cls")
+ else:
+ os.system("clear")
+
+def display_interface():
+ #"Takes Resizer objects."
+ resizer = Resizer()
+ __clear()
+
+ choice = " "
+ exit_menu = False
+ __print_intro()
+ while not exit_menu:
+ __print_menu()
+ choice = raw_input("Choice: ")
+ print
+
+ # Set source path
+ if choice == '1':
+ path = raw_input("Please enter the path for the file(s) you would like to resize: ")
+ resizer.set_imgpath(path)
+ print resizer.img_path()
+ raw_input()
+
+ # Set destination path
+ elif choice == '2':
+ dest = raw_input("Please enter the path where you would like your resized file(s) to go: ")
+ resizer.set_destination(dest)
+
+ # Set file suffix
+ elif choice == '3':
+ suffix = raw_input("Please enter the what suffix you would like your resized file(s) to have: ")
+ resizer.set_suffix(suffix)
+
+ # Set max file size
+ elif choice == '4':
+ max_size = raw_input("Please enter the maximum file size you would like your resized file(s) to have (in Kilobytes [KB]): ")
+ resizer.set_max_size(max_size)
+
+ # Set resolution
+ elif choice == '5':
+ res = raw_input("Please enter the [horizontal] resolution you would like your resized file(s) to have: ")
+ resizer.set_resolution(res)
+
+ # Upload
+ elif choice == '6':
+ raw_input("This feature has not yet been implemented.")
+
+ # Resize
+ elif choice == '7':
+ if not resizer.img_path():
+ print "ERROR: Please provide a Source for the Image(s) in option 1 before proceeding."
+ else:
+ resizer.resize()
+ exit_menu = True
+
+ # Help
+ elif choice == '8':
+ __print_help()
+
+ # Exit
+ elif choice == '9':
+ print "Goodbye!"
+ exit_menu = True
+
+ else:
+ print "ERROR: Please enter a number between 1 and 9."
+
+
@@ -0,0 +1,52 @@
+# Program: Image Resizer
+# Module Description: Command Line Argument Parser
+# Author: Enrique Gavidia
+# E-mail: enrique@enriquegavidia.com
+# License: TBD
+# Date: 2008-2010
+
+from os import getcwd
+from os.path import abspath
+from optparse import OptionParser
+
+def parse_paths():
+ '''
+ Parse commandline input for a source path, and destination path.
+ Returns the results in a list.
+ '''
+
+ parse_list = OptionParser()
+ _opts, paths = parse_list.parse_args()
+ return paths
+
+def get_paths(path = '', destination = ''):
+ '''
+ Default method for getting the source and destination paths.
+ Defaults to reading commandline input if no paramaters are given.
+ '''
+
+ imgpath, dest = path, destination
+
+ # if either of the paramaters is not present, parse commandline input
+ # and store it as a list in 'paths'
+ if not imgpath or not dest:
+ paths = parse_paths()
+
+ # attempt to retrieve the source path from 'paths', if not present,
+ # return empty string for other behaviors to handle.
+ if not imgpath:
+ try:
+ imgpath = abspath(paths[0])
+ except:
+ imgpath = ''
+
+ # attempt to retrieve the destination path from 'paths', if not present,
+ # return current directory.
+ if not dest:
+ try:
+ dest = abspath(paths[1]) + '/'
+ except:
+ dest = getcwd()+'/'
+
+ return imgpath, dest
+
Oops, something went wrong.

0 comments on commit beba031

Please sign in to comment.