#!/usr/bin/envpython##pic2htmlv0.2a##Asmallcgi-scripttoconvertbinary-picturesto#colorizedhtml-data.##Author:RikardBosnjakovicbos@hack.org,2001-03-27#updated2003-09-08#updated2004-08-01#importcgi,Image
,os,StringIO,sys,tempfile,urllibprint"Content-type:text/html\n"#maxsize(widthorheight,inpixels)MAXSIZE=200#readthefiletouseasthebackgroundandremoveallcrappycharstxt=open("source").read()foriin"\n":txt
=txt.replace(i,"")#gettheurltothepicturestorage=cgi.FieldStorage()ifnotstorage.has_key("url"):print"EmptyURL."sys.exit()url=storage["url"].valueifurllib.unquote(url).find("file://")-1:print"Notallowed
tousefile://."sys.exit()try:urlfile=urllib.urlopen(url)exceptIOError:print"Anerroroccuredwhileretrievingthefile."sys.exit()pagedata=urlfile.read()try:im=Image.open(StringIO.StringIO(pagedata))except:p
rint"ERROR-",sys.exc_type,":",sys.exc_valueprint#print"Ifthedebuginfoabovewastoocryptic,thentheauthorstillwouldliketoseeit!"sys.exit()##grayscalepicturesdoesn'tworkyet.#isthecoloraninteger(index)oratu
ple(palette)?iftype(im.getpixel((0,0)))==type(0):#palette.obtainitandputtheminalistof3-tuples(R,G,B)palette=im.getdata().getpalette()pal=[tuple(palette[3*i:3*i+3])foriinrange(len(palette)/3)]else:#the
paletteisstoredineachpixel,notindexedpal=()#rescalethepicturetobetterproportionalsx=im.size[0]y=im.size[1]ifx1000ory1000:print"Toobigpicture,tryasmallerone(below1000*1000)."sys.exit()ifxMAXSIZE:im=im.
resize((MAXSIZE,(MAXSIZE*y)/x))x=im.size[0]y=im.size[1]ifyMAXSIZE:im=im.resize(((MAXSIZE*x)/y,MAXSIZE))im=im.resize((im.size[0],im.size[1]/2))#printthepictureinasciiandsaveittempfile.tempdir="/home/bo
s/public_html/pic2html/tmp/"tmpname=tempfile.mktemp(".html")f=open(tmpname,"a")pagedata="htmlheadtitlepic2htmlv0.2lt;bos@hack.org"pagedata+="gt;/title/head"pagedata+='bodybgcolor="#000000"basefontsize
=1pre'printpagedataf.write(pagedata+"\n")filecount=0lastcol=()newcol=()foryinrange(im.size[1]):pagedata="font"forxinrange(im.size[0]):ifpal:newcol=pal[im.getpixel((x,y))]coltuple=tuple(map(ord,newcol)
)else:newcol=coltuple=im.getpixel((x,y))ifnotnewcol==lastcol:pagedata+="/fontfontcolor=#%02x%02x%02x"%coltuplelastcol=newcolpagedata+=txt[filecount]filecount+=1iffilecountlen(txt)-1:filecount=0printpa
gedataf.write(pagedata+"\n")pagedata="/pre/basefont/body"printpagedataf.write(pagedata+"\n")f.close()#logtherequestifos.environ.has_key("REMOTE_HOST"):host=os.environ["REMOTE_HOST"]else:host=os.enviro
n["REMOTE_ADDR"]log=open("log.txt","a")log.write(host+"-"+url+"-("+tmpname+")\n")log.close()#!/usr/bin/envpython##pic2htmlv0.2a##Asmallcgi-scripttoconvertbinary-picturesto#colorizedhtml-data.##Author:
RikardBosnjakovicbos@hack.org,2001-03-27#updated2003-09-08#updated2004-08-01#importcgi,Image,os,StringIO,sys,tempfile,urllibprint"Content-type:text/html\n"#maxsize(widthorheight,inpixels)MAXSIZE=200#r
eadthefiletouseasthebackgroundandremoveallcrappycharstxt=open("source").read()foriin"\n":txt=txt.replace(i,"")#gettheurltothepicturestorage=cgi.FieldStorage()ifnotstorage.has_key("url"):print"EmptyURL
."sys.exit()url=storage["url"].valueifurllib.unquote(url).find("file://")-1:print"Notallowedtousefile://."sys.exit()try:urlfile=urllib.urlopen(url)exceptIOError:print"Anerroroccuredwhileretrievingthef
ile."sys.exit()pagedata=urlfile.read()try:im=Image.open(StringIO.StringIO(pagedata))except:print"ERROR-",sys.exc_type,":",sys.exc_valueprint#print"Ifthedebuginfoabovewastoocryptic,thentheauthorstillwo
uldliketoseeit!"sys.exit()##grayscalepicturesdoesn'tworkyet.#isthecoloraninteger(index)oratuple(palette)?iftype(im.getpixel((0,0)))==type(0):#palette.obtainitandputtheminalistof3-tuples(R,G,B)palette=
im.getdata().getpalette()pal=[tuple(palette[3*i:3*i+3])foriinrange(len(palette)/3)]else:#thepaletteisstoredineachpixel,notindexedpal=()#rescalethepicturetobetterproportionalsx=im.size[0]y=im.size[1]if
x1000ory1000:print"Toobigpicture,tryasmallerone(below1000*1000)."sys.exit()ifxMAXSIZE:im=im.resize((MAXSIZE,(MAXSIZE*y)/x))x=im.size[0]y=im.size[1]ifyMAXSIZE:im=im.resize(((MAXSIZE*x)/y,MAXSIZE))im=im
.resize((im.size[0],im.size[1]/2))#printthepictureinasciiandsaveittempfile.tempdir="/home/bos/public_html/pic2html/tmp/"tmpname=tempfile.mktemp(".html")f=open(tmpname,"a")pagedata="htmlheadtitlepic2ht
mlv0.2lt;bos@hack.org"pagedata+="gt;/title/head"pagedata+='bodybgcolor="#000000"basefontsize=1pre'printpagedataf.write(pagedata+"\n")filecount=0lastcol=()newcol=()foryinrange(im.size[1]):pagedata="fon
t"forxinrange(im.size[0]):ifpal:newcol=pal[im.getpixel((x,y))]coltuple=tuple(map(ord,newcol))else:newcol=coltuple=im.getpixel((x,y))ifnotnewcol==lastcol:pagedata+="/fontfontcolor=#%02x%02x%02x"%coltup
lelastcol=newcolpagedata+=txt[filecount]filecount+=1iffilecountlen(txt)-1:filecount=0printpagedataf.write(pagedata+"\n")pagedata="/pre/basefont/body"printpagedataf.write(pagedata+"\n")f.close()#logthe
requestifos.environ.has_key("REMOTE_HOST"):host=os.environ["REMOTE_HOST"]else:host=os.environ["REMOTE_ADDR"]log=open("log.txt","a")log.write(host+"-"+url+"-("+tmpname+")\n")log.close()#!/usr/bin/envpy
thon##pic2htmlv0.2a##Asmallcgi-scripttoconvertbinary-picturesto#colorizedhtml-data.##Author:RikardBosnjakovicbos@hack.org,2001-03-27#updated2003-09-08#updated2004-08-01#importcgi,Image,os,StringIO,sys
,tempfile,urllibprint"Content-type:text/html\n"#maxsize(widthorheight,inpixels)MAXSIZE=200#readthefiletouseasthebackgroundandremoveallcrappycharstxt=open("source").read()foriin"\n":txt=txt.replace(i,"
")#gettheurltothepicturestorage=cgi.FieldStorage()ifnotstorage.has_key("url"):print"EmptyURL."sys.exit()url=storage["url"].valueifurllib.unquote(url).find("file://")-1:print"Notallowedtousefile://."sy
s.exit()try:urlfile=urllib.urlopen(url)exceptIOError:print"Anerroroccuredwhileretrievingthefile."sys.exit()pagedata=urlfile.read()try:im=Image.open(StringIO.StringIO(pagedata))except:print"ERROR-",sys
.exc_type,":",sys.exc_valueprint#print"Ifthedebuginfoabovewastoocryptic,thentheauthorstillwouldliketoseeit!"sys.exit()##grayscalepicturesdoesn'tworkyet.#isthecoloraninteger(index)oratuple(palette)?ift
ype(im.getpixel((0,0)))==type(0):#palette.obtainitandputtheminalistof3-tuples(R,G,B)palette=im.getdata().getpalette()pal=[tuple(palette[3*i:3*i+3])foriinrange(len(palette)/3)]else:#thepaletteisstoredi
neachpixel,notindexedpal=()#rescalethepicturetobetterproportionalsx=im.size[0]y=im.size[1]ifx1000ory1000:print"Toobigpicture,tryasmallerone(below1000*1000)."sys.exit()ifxMAXSIZE:im=im.resize((MAXSIZE,
(MAXSIZE*y)/x))x=im.size[0]y=im.size[1]ifyMAXSIZE:im=im.resize(((MAXSIZE*x)/y,MAXSIZE))im=im.resize((im.size[0],im.size[1]/2))#printthepictureinasciiandsaveittempfile.tempdir="/home/bos/public_html/pi
c2html/tmp/"tmpname=tempfile.mktemp(".html")f=open(tmpname,"a")pagedata="htmlheadtitlepic2htmlv0.2lt;bos@hack.org"pagedata+="gt;/title/head"pagedata+='bodybgcolor="#000000"basefontsize=1pre'printpaged
ataf.write(pagedata+"\n")filecount=0lastcol=()newcol=()foryinrange(im.size[1]):pagedata="font"forxinrange(im.size[0]):ifpal:newcol=pal[im.getpixel((x,y))]coltuple=tuple(map(ord,newcol))else:newcol=col
tuple=im.getpixel((x,y))ifnotnewcol==lastcol:pagedata+="/fontfontcolor=#%02x%02x%02x"%coltuplelastcol=newcolpagedata+=txt[filecount]filecount+=1iffilecountlen(txt)-1:filecount=0printpagedataf.write(pa
gedata+"\n")pagedata="/pre/basefont/body"printpagedataf.write(pagedata+"\n")f.close()#logtherequestifos.environ.has_key("REMOTE_HOST"):host=os.environ["REMOTE_HOST"]else:host=os.environ["REMOTE_ADDR"]
log=open("log.txt","a")log.write(host+"-"+url+"-("+tmpname+")\n")log.close()#!/usr/bin/envpython##pic2htmlv0.2a##Asmallcgi-scripttoconvertbinary-picturesto#colorizedhtml-data.##Author:RikardBosnjakovi
cbos@hack.org,2001-03-27#updated2003-09-08#updated2004-08-01#importcgi,Image,os,StringIO,sys,tempfile,urllibprint"Content-type:text/html\n"#maxsize(widthorheight,inpixels)MAXSIZE=200#readthefiletousea
sthebackgroundandremoveallcrappycharstxt=open("source").read()foriin"\n":txt=txt.replace(i,"")#gettheurltothepicturestorage=cgi.FieldStorage()ifnotstorage.has_key("url"):print"EmptyURL."sys.exit()url=
storage["url"].valueifurllib.unquote(url).find("file://")-1:print"Notallowedtousefile://."sys.exit()try:urlfile=urllib.urlopen(url)exceptIOError:print"Anerroroccuredwhileretrievingthefile."sys.exit()p
agedata=urlfile.read()try:im=Image.open(StringIO.StringIO(pagedata))except:print"ERROR-",sys.exc_type,":",sys.exc_valueprint#print"Ifthedebuginfoabovewastoocryptic,thentheauthorstillwouldliketoseeit!"
sys.exit()##grayscalepicturesdoesn'tworkyet.#isthecoloraninteger(index)oratuple(palette)?iftype(im.getpixel((0,0)))==type(0):#palette.obtainitandputtheminalistof3-tuples(R,G,B)palette=im.getdata().get
palette()pal=[tuple(palette[3*i:3*i+3])foriinrange(len(palette)/3)]else:#thepaletteisstoredineachpixel,notindexedpal=()#rescalethepicturetobetterproportionalsx=im.size[0]y=im.size[1]ifx1000ory1000:pri
nt"Toobigpicture,tryasmallerone(below1000*1000)."sys.exit()ifxMAXSIZE:im=im.resize((MAXSIZE,(MAXSIZE*y)/x))x=im.size[0]y=im.size[1]ifyMAXSIZE:im=im.resize(((MAXSIZE*x)/y,MAXSIZE))im=im.resize((im.size
[0],im.size[1]/2))#printthepictureinasciiandsaveittempfile.tempdir="/home/bos/public_html/pic2html/tmp/"tmpname=tempfile.mktemp(".html")f=open(tmpname,"a")pagedata="htmlheadtitlepic2htmlv0.2lt;bos@hac
k.org"pagedata+="gt;/title/head"pagedata+='bodybgcolor="#000000"basefontsize=1pre'printpagedataf.write(pagedata+"\n")filecount=0lastcol=()newcol=()foryinrange(im.size[1]):pagedata="font"forxinrange(im
.size[0]):ifpal:newcol=pal[im.getpixel((x,y))]coltuple=tuple(map(ord,newcol))else:newcol=coltuple=im.getpixel((x,y))ifnotnewcol==lastcol:pagedata+="/fontfontcolor=#%02x%02x%02x"%coltuplelastcol=newcol
pagedata+=txt[filecount]filecount+=1iffilecountlen(txt)-1:filecount=0printpagedataf.write(pagedata+"\n")pagedata="/pre/basefont/body"printpagedataf.write(pagedata+"\n")f.close()#logtherequestifos.envi
ron.has_key("REMOTE_HOST"):host=os.environ["REMOTE_HOST"]else:host=os.environ["REMOTE_ADDR"]log=open("log.txt","a")log.write(host+"-"+url+"-("+tmpname+")\n")log.close()#!/usr/bin/envpython##pic2htmlv0
.2a##Asmallcgi-scripttoconvertbinary-picturesto#colorizedhtml-data.##Author:RikardBosnjakovicbos@hack.org,2001-03-27#updated2003-09-08#updated2004-08-01#importcgi,Image,os,StringIO,sys,tempfile,urllib
print"Content-type:text/html\n"#maxsize(widthorheight,inpixels)MAXSIZE=200#readthefiletouseasthebackgroundandremoveallcrappycharstxt=open("source").read()foriin"\n":txt=txt.replace(i,"")#gettheurltoth
epicturestorage=cgi.FieldStorage()ifnotstorage.has_key("url"):print"EmptyURL."sys.exit()url=storage["url"].valueifurllib.unquote(url).find("file://")-1:print"Notallowedtousefile://."sys.exit()try:urlf
ile=urllib.urlopen(url)exceptIOError:print"Anerroroccuredwhileretrievingthefile."sys.exit()pagedata=urlfile.read()try:im=Image.open(StringIO.StringIO(pagedata))except:print"ERROR-",sys.exc_type,":",sy
s.exc_valueprint#print"Ifthedebuginfoabovewastoocryptic,thentheauthorstillwouldliketoseeit!"sys.exit()##grayscalepicturesdoesn'tworkyet.#isthecoloraninteger(index)oratuple(palette)?iftype(im.getpixel(
(0,0)))==type(0):#palette.obtainitandputtheminalistof3-tuples(R,G,B)palette=im.getdata().getpalette()pal=[tuple(palette[3*i:3*i+3])foriinrange(len(palette)/3)]else:#thepaletteisstoredineachpixel,notin
dexedpal=()#rescalethepicturetobetterproportionalsx=im.size[0]y=im.size[1]ifx1000ory1000:print"Toobigpicture,tryasmallerone(below1000*1000)."sys.exit()ifxMAXSIZE:im=im.resize((MAXSIZE,(MAXSIZE*y)/x))x
=im.size[0]y=im.size[1]ifyMAXSIZE:im=im.resize(((MAXSIZE*x)/y,MAXSIZE))im=im.resize((im.size[0],im.size[1]/2))#printthepictureinasciiandsaveittempfile.tempdir="/home/bos/public_html/pic2html/tmp/"tmpn
ame=tempfile.mktemp(".html")f=open(tmpname,"a")pagedata="htmlheadtitlepic2htmlv0.2lt;bos@hack.org"pagedata+="gt;/title/head"pagedata+='bodybgcolor="#000000"basefontsize=1pre'printpagedataf.write(paged
ata+"\n")filecount=0lastcol=()newcol=()foryinrange(im.size[1]):pagedata="font"forxinrange(im.size[0]):ifpal:newcol=pal[im.getpixel((x,y))]coltuple=tuple(map(ord,newcol))else:newcol=coltuple=im.getpixe
l((x,y))ifnotnewcol==lastcol:pagedata+="/fontfontcolor=#%02x%02x%02x"%coltuplelastcol=newcolpagedata+=txt[filecount]filecount+=1iffilecountlen(txt)-1:filecount=0printpagedataf.write(pagedata+"\n")page
data="/pre/basefont/body"printpagedataf.write(pagedata+"\n")f.close()#logtherequestifos.environ.has_key("REMOTE_HOST"):host=os.environ["REMOTE_HOST"]else:host=os.environ["REMOTE_ADDR"]log=open("log.tx
t","a")log.write(host+"-"+url+"-("+tmpname+")\n")log.close()#!/usr/bin/envpython##pic2htmlv0.2a##Asmallcgi-scripttoconvertbinary-picturesto#colorizedhtml-data.##Author:RikardBosnjakovicbos@hack.org,20
01-03-27#updated2003-09-08#updated2004-08-01#importcgi,Image,os,StringIO,sys,tempfile,urllibprint"Content-type:text/html\n"#maxsize(widthorheight,inpixels)MAXSIZE=200#readthefiletouseasthebackgroundan
dremoveallcrappycharstxt=open("source").read()foriin"\n":txt=txt.replace(i,"")#gettheurltothepicturestorage=cgi.FieldStorage()ifnotstorage.has_key("url"):print"EmptyURL."sys.exit()url=storage["url"].v
alueifurllib.unquote(url).find("file://")-1:print"Notallowedtousefile://."sys.exit()try:urlfile=urllib.urlopen(url)exceptIOError:print"Anerroroccuredwhileretrievingthefile."sys.exit()pagedata=urlfile.
read()try:im=Image.open(StringIO.StringIO(pagedata))except:print"ERROR-",sys.exc_type,":",sys.exc_valueprint#print"Ifthedebuginfoabovewastoocryptic,thentheauthorstillwouldliketoseeit!"sys.exit()##gray
scalepicturesdoesn'tworkyet.#isthecoloraninteger(index)oratuple(palette)?iftype(im.getpixel((0,0)))==type(0):#palette.obtainitandputtheminalistof3-tuples(R,G,B)palette=im.getdata().getpalette()pal=[tu
ple(palette[3*i:3*i+3])foriinrange(len(palette)/3)]else:#thepaletteisstoredineachpixel,notindexedpal=()#rescalethepicturetobetterproportionalsx=im.size[0]y=im.size[1]ifx1000ory1000:print"Toobigpicture
,tryasmallerone(below1000*1000)."sys.exit()ifxMAXSIZE:im=im.resize((MAXSIZE,(MAXSIZE*y)/x))x=im.size[0]y=im.size[1]ifyMAXSIZE:im=im.resize(((MAXSIZE*x)/y,MAXSIZE))im=im.resize((im.size[0],im.size[1]/2
))#printthepictureinasciiandsaveittempfile.tempdir="/home/bos/public_html/pic2html/tmp/"tmpname=tempfile.mktemp(".html")f=open(tmpname,"a")pagedata="htmlheadtitlepic2htmlv0.2lt;bos@hack.org"pagedata+=
"gt;/title/head"pagedata+='bodybgcolor="#000000"basefontsize=1pre'printpagedataf.write(pagedata+"\n")filecount=0lastcol=()newcol=()foryinrange(im.size[1]):pagedata="font"forxinrange(im.size[0]):ifpal:
newcol=pal[im.getpixel((x,y))]coltuple=tuple(map(ord,newcol))else:newcol=coltuple=im.getpixel((x,y))ifnotnewcol==lastcol:pagedata+="/fontfontcolor=#%02x%02x%02x"%coltuplelastcol=newcolpagedata+=txt[fi
lecount]filecount+=1iffilecountlen(txt)-1:filecount=0printpagedataf.write(pagedata+"\n")pagedata="/pre/basefont/body"printpagedataf.write(pagedata+"\n")f.close()#logtherequestifos.environ.has_key("REM
OTE_HOST"):host=os.environ["REMOTE_HOST"]else:host=os.environ["REMOTE_ADDR"]log=open("log.txt","a")log.write(host+"-"+url+"-("+tmpname+")\n")log.close()#!/usr/bin/envpython##pic2htmlv0.2a##Asmallcgi-s