-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimginfo.py
executable file
·66 lines (62 loc) · 2.8 KB
/
imginfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
################################################################################
################## ### ### ########### ### ### #####################
################## ## ## ## ## ## ########## ## ## ## ## ## ####################
################## # ### ## ## ## ########## # ### ## ## ## ####################
################## ## ### ### ########### ## ### ### #####################
################################################################################
## ##
## Copyright 2010 Ian Daniher <[email protected]> ##
## ##
## Licensed under the GPLv3 or later, ##
## see PERMISSION for copying permission ##
## and COPYING for the GPL License ##
## ##
################################################################################
################################################################################
import os, re
import Image
import Queue
# needs PIL
pics = []
size = []
format = []
mode = []
images_dir = 'data/hires/'
def imginfo(dir):
dir_queue = Queue.Queue(0)
dir_queue.put(dir)
# while not dir_queue.empty():
while True:
dir = dir_queue.get()
print 'dir: ' + dir
items_in_dir = os.listdir(dir)
# makes a list of the items in dir, a word in dirlist
for item in items_in_dir:
pathtoitem=dir+'/'+item
# defines pathtoitem as a direction to a
if os.path.isfile(pathtoitem):
print pathtoitem
try:
Image.open(pathtoitem)
# checks to see if the file located at pathtoitem is an image by attempting to open it with PIL
pics.append(pathtoitem)
# if it's an image, append the path to the 'pics' list
except IOError:
print "item located at " + pathtoitem + " is unopenable by PIL"
except:
print "something terrible and unexpected has happened. run for your life."
# if we're looking at a dir:
else:
pathtoitem=dir+'/'+item
print pathtoitem
dir_queue.put(pathtoitem)
import pdb; pdb.set_trace()
for pic in pics:
im = Image.open(pic)
size.append(list(im.size))
format.append(im.format)
mode.append(im.mode)
array = [ pics, size, format, mode ]
return array
if __name__ == "__main__":
print imginfo(images_dir)