(* Compressing pictures to preview format *) Clear["@"]; (********** INPUT STARTS **********) {minrollwork,maxrollwork}={175,999}; (* HTML/pictures/archives-directory *) dir0="d:\\html\\pictures\\archives"; (* working directory *) dirwork="d:\\sergeev\\bgu\\html\\maintain"; (* temp. file *) temp="d:\\temp\\tempcomp"; itest=0; (* 1 for testing *) iprint=0; newcomp=0; (* wheather to compress even if it exists *) (********** INPUT ENDS **********) SetDirectory[dirwork]; <maxrollwork,Continue[]]; pics0=pics[roll]; mpics0=mpics[roll]; If[mpics0==0,Continue[]]; SetDirectory[diryear]; dirroll=ToFileName[{dircomp,year,roll}]; If[FileType[dirroll]=!=Directory, CreateDirectory[roll]; SetDirectory[roll]; CreateDirectory["jpeg"]; ]; colorsfile=ToFileName[dirroll,"colors.dat"]; os=OpenWrite[colorsfile,PageWidth->Infinity,FormatType->OutputForm]; Do[pic=pics0[[npic]]; picfile=ToFileName[{dirroll,"jpeg"},pic]; picfile0=ToFileName[{dir0,year,roll,"jpeg"},pic]; SetDirectory[ToFileName[{dir0,year,roll,"jpeg"}]]; Run["convert "<>pic<>" "<>temp<>".xbm"]; s=OpenRead[temp<>".xbm"]; {w,h}=Read[s,{String,String}]; Close[s]; as=ReadList[StringToStream[w],Word]//Last; bs=ReadList[StringToStream[h],Word]//Last; a=as//ToExpression; b=bs//ToExpression; n=If[a".bat",PageWidth->Infinity,FormatType->OutputForm]; If[FileType[picfile]=!=File || newcomp=!=0, Write[s,"convert -crop "<>ToString[m]<>"x"<>ToString[m]<>"+"<>ToString[j]<> "+"<>ToString[k]<>" -quality 30 -sharpen 50% -geometry 360x360 -raise 6 -frame 8 -normalize "<> picfile0<>" "<>picfile] ]; If[itest==0, Write[s,"convert "<>picfile<>" "<>temp<>".histogram"], Write[s,"convert -geometry 100x100 "<>picfile<>" "<>temp<>".histogram"] ]; Write[s,"sed -n \"/: (/p\" "<>temp<>".histogram >"<>temp<>".col"]; Write[s,"sed -e \"s/:/ /g\" -e \"s/(/ /g\" -e \"s/)/ /g\" -e \"s/,/ /g\" "<>temp<>".col >"<>temp<>".txt"]; Close[s]; Run[temp<>".bat"]; hist=ReadList[temp<>".txt",{Number,Number,Number,Number,String}]; mhist=Length[hist]; r=g=b=m=0; Do[col=hist[[nhist]]; {m1,r1,g1,b1}=Take[col,4]; m=m+m1; r=r+m1 r1; g=g+m1 g1; b=b+m1 b1; ,{nhist,mhist}]; {r,g,b}=Floor[{r,g,b}/m+{1,1,1}/2]; {r,g,b}=ToString/@{r,g,b}; Write[os,pic<>" "<>as<>" "<>bs<> " "<>r<>" "<>g<>" "<>b ]; ,{npic,mpics0}]; Close[os]; ,{nroll,mrolls0}]; ,{nyear,myears}];