ImageList.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python
  2. import Image
  3. import sys
  4. import fnmatch
  5. import os
  6. the_path = sys.argv[1]
  7. files = []
  8. for root, dirnames, filenames in os.walk(the_path):
  9. for filename in fnmatch.filter(filenames, '*.png'):
  10. files.append(os.path.join(root, filename))
  11. htmlPrefix = '''<html>
  12. <head>
  13. <style type="text/css">
  14. body { background-color:#e4e8e9; }
  15. table {
  16. border:none;
  17. border-collapse: collapse;
  18. }
  19. table td {
  20. border-bottom: 1px solid #000;
  21. padding: 10px
  22. }
  23. table td:first-child {
  24. border-left: none;
  25. }
  26. table td:last-child {
  27. border-right: none;
  28. }
  29. td { font-family:"Tahoma"; }
  30. img { max-width:300px;
  31. height:auto
  32. }
  33. </style>
  34. </head>
  35. <body>'''
  36. htmlSuffix = '''</body>
  37. </html>'''
  38. body = ""
  39. body+= "<table>"
  40. for file in files:
  41. img = Image.open(file)
  42. path,filename = os.path.split(file)
  43. width,height = img.size
  44. body+= r'<tr><td>'+'<a href="'+file+'"><img src='+file+'></a>'+'</td><td>'+ filename + ", " + str(width)+ " x " +str(height) +r'</td></tr>'
  45. body+= "</table>"
  46. f = open('index.html', 'w')
  47. f.write(htmlPrefix+body+htmlSuffix)