📜 ⬆️ ⬇️

Sort images by resolution using Python and PIL

image

I wanted to register on Habré, but since I don’t have much knowledge, but the audience is just the opposite, I decided to try to lay out a script on a python that I wrote at the request of a friend for a bottle of 7apa :) I also helped the script writer to organize the dump of pictures ~ 15GB.

The script passes through the directory and creates in it the folders of the Height Widths view and shoves there corresponding images in the resolution.
')
PS The mistakes are not made by the one who does nothing.



Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  1. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  2. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  3. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  4. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  5. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  6. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  7. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  8. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  9. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  10. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  11. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  12. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  13. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  14. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  15. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  16. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  17. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  18. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  19. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  20. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  21. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  22. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  23. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  24. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  25. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  26. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  27. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  28. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  29. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  30. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  31. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  32. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  33. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  34. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  35. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  36. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  37. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  38. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  39. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  40. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  41. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  42. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  43. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  44. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)
  45. Copy Source | Copy HTML #!/usr/bin/env python # -*- coding: UTF-8 -*- """ sorts images by resolution""" import os,sys from PIL import Image # dirname = os .path.abspath( sys .argv[ 1 ]) try : newdir = os .path.abspath( sys .argv[ 2 ]) except : newdir = dirname def image_sort (dirname, newdir, recur= 0 ): if not recur: print 'sorting started ...' # else : print 'sorting started in %s...' %dirname # # imagelist = [] if os .path.isdir(dirname): for x in os .listdir(dirname): absx = dirname+ os .sep+x if os .path.isfile(absx):imagelist.append(absx) else : #print 'summon subsort in %s'%x image_sort (absx, newdir+ os .sep+x,recur= 1 ) # / for name in imagelist: try : resolution = Image. open (name).size # except IOError: print 'seems not image: ' + name, '/n' continue imdir = '%sx%s' %(resolution[ 0 ],resolution[ 1 ]) imdir = os .path.join(newdir,imdir) # if os .path.split(dirname)[- 1 ] == os .path.split(imdir)[- 1 ]: continue elif not os .path.exists(imdir): #print 'making dir %s'%imdir os .mkdir(imdir) try : os .system( 'move "%s" "%s"' %(name,imdir)) except WindowsError: print 'error with ' + name, '/n' if not recur: print 'sorting completed!' if __name__ == '__main__' : image_sort (dirname, newdir)

Source: https://habr.com/ru/post/85306/


All Articles