Created
July 28, 2012 09:11
ImageSave
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
path = '/home/rishi/Documents/' | |
fname = 'MyImg' | |
#fname = '' | |
if path: | |
import glob, re, os, tempfile | |
if fname: | |
if os.path.exists(path): | |
if path[-1]!='/': path+='/' | |
gpath = path + fname + "*.png" | |
current_images = glob.glob(gpath) | |
nums = [0] | |
for img in current_images: | |
i = os.path.splitext(img)[0].split('/')[-1][-4:] | |
try: | |
num = re.findall('[0-9]+$', i)[0] | |
nums.append(int(num)) | |
except IndexError: | |
pass | |
nums.sort() | |
new_num = nums[-1]+1 | |
file_suffix = '%04d.png'%(new_num) | |
filename = tempfile.NamedTemporaryFile(prefix=fname, suffix=file_suffix, dir=path) | |
else: | |
print "wrong path" | |
else: | |
if os.path.exists(path): | |
import glob, re, os, tempfile | |
if path[-1]!='/': path+='/' | |
gpath = path + "Image*.png" | |
current_images = glob.glob(gpath) | |
nums = [0] | |
for img in current_images: | |
i = os.path.splitext(img)[0].split('/')[-1][-4:] | |
try: | |
num = re.findall('[0-9]+$', i)[0] | |
nums.append(int(num)) | |
except IndexError: | |
pass | |
nums.sort() | |
new_num = nums[-1]+1 | |
file_suffix = '%04d.png'%(new_num) | |
filename = tempfile.NamedTemporaryFile(prefix='Image', suffix=file_suffix, dir=path) | |
else: | |
print "wrong path" | |
else: | |
print "Path is not optional" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment