#!/usr/local/bin/python #-*- coding: utf-8 -*- # uruchamianie: pwd|python img.py #--------------------------------------------------------- rozszerzenia=["*.JPG","*.jpg","*.JPEG","*.jpeg"] obraz_rozmiar=320, 200 ilosc_kolumn=3 html_index="index.html" html_title="Galeria" html_bgcolor="black" html_textcolor="gray" html_tableborder="0" html_table_cellspacing="0" html_table_cellpadding="20" html_link="#FFFFFF" html_link_visited="#999999" html_link_active="#C0C0C0" html_link_hover="#FFFFFF" html_link_hover_bg="#111111" html_czcionka="monospace" html_czcionka_rozmiar="10px" #--------------------------------------------------------- import os,sys,getopt,getpass,Image from fnmatch import fnmatch katalog=raw_input() pliki=[] tytul=(html_title) + ' by ' + getpass.getuser() def sprawdz_katalogi(): if not os.path.exists(katalog + "/miniaturki"): print "Brak katalogu \"miniaturki\"...", os.makedirs(katalog + "/miniaturki") print "utworzony." def listowanie(): print 'Tworze liste obrazow...', for plik in os.listdir(katalog): if fnmatch(plik, "*.jpg")\ or fnmatch(plik, "*.jpeg")\ or fnmatch(plik, "*.JPG")\ or fnmatch(plik, "*.JPEG"): pliki.append(plik) print 'znaleziono %s plikow JPG i PNG.' % (len(pliki)) if len(pliki)==0: sys.exit() def zrob_miniaturki(): for plik in pliki[:]: print ('Zmniejszam plik ' + (plik) + '...'), file, ext = os.path.splitext(plik) try: obraz=Image.open(plik) obraz.thumbnail(obraz_rozmiar, Image.ANTIALIAS) obraz.save("miniaturki/mini_" + file + ".jpg", "JPEG") print ('gotowe') except IOError, err: print "COS JEST ZJEBANE" # dodac usuwanie z listy - moze zostawia puste pola def tworzenie_html(): print 'Tworze ' + (html_index) + '...', def wiersz(alist, sublen): return [alist[i:i+sublen] for i in range(0, len(alist), sublen)] index=open((html_index),'w') index.write ('\n\n \n') index.write (' \n') index.write (' \n') index.write (' ' + (tytul) + '\n \n') index.write (' \n') index.write (' \n') index.write (' \n') for pliki[:] in wiersz(pliki[:],ilosc_kolumn): index.write (' \n') for pliki[:] in wiersz(pliki[:],1): for x in pliki[:]: index.write ('
' + x + '
\n') index.write (' \n') index.write (' \n \n') index.write ('

\n') index.write (' Valid HTML 4.01 Transitional

\n') index.write ('

Created with img.py

') index.write (' \n\n') print 'gotowe' index.close() def main(): listowanie() sprawdz_katalogi() zrob_miniaturki() wiersze=len(pliki)/3+1 tworzenie_html() if __name__ == "__main__": sys.exit(main())