import sys,os import anduril import anduril.table from anduril.args import * import shutil #import PythonMagick import subprocess,csv def choiceListGenerator(csvFile,chooseCols, imgCol): if csvFile==None: return ("","") reader=anduril.table.TableReader(csvFile,type='dict',column_types=str) chooseNames=[x.strip() for x in chooseCols.split(",")] DDMenus="" js='''''' return (js,DDMenus) inImages = input_in outImages = output_out os.mkdir(outImages) (js,DDMenus)=choiceListGenerator(input_menuChoices, param_choiceCols, param_imageCol) if input_css!=None: style=open(input_css, 'r').read() else: style=open('default.css', 'r').read() index = open(outImages+'/index.html', 'w') index.write(''' %s '''%(param_title,style)) pageWidth = int(param_pageWidth) width = float(100)/int(param_columns) index.write('''

%s

'''%(pageWidth,param_head)) def noChoices(): pdfList = "" for imageFile in sorted(os.listdir(inImages)): if os.path.isfile(os.path.join(inImages, imageFile)): base, extension = os.path.splitext(imageFile) writeImage = False if(getImages==True): fileName=imageFile if(extension == '.pdf' and convertPdf == True) : fileName = base + ".jpg" convargs=['convert','-density','300x300',os.path.join(inImages, imageFile)+'[0]','-background','white','-flatten','-quality','97',os.path.join(outImages, fileName)] convp=subprocess.call(convargs) elif(extension <> '.pdf'): shutil.copy(os.path.join(inImages, imageFile), os.path.join(outImages, imageFile)) index.write(''%(fileName,fileName,str(width))) if(extension == '.pdf' and getPdf): shutil.copy(os.path.join(inImages, imageFile), os.path.join(outImages, imageFile)) pdfList = pdfList + '

'+imageFile+'

' #except IOError: # continue index.write('''
%s '''%(pdfList,)) def withChoices(): index.write('''
%s '''%(DDMenus,js)) for imageFile in sorted(os.listdir(inImages)): if os.path.isfile(os.path.join(inImages, imageFile)): base, extension = os.path.splitext(imageFile) writeImage = False if(getImages==True): fileName=imageFile if(extension == '.pdf' and convertPdf == True): fileName = imageFile + ".png" convargs=['convert','-density','300x300',os.path.join(inImages, imageFile)+'[0]','-background','white','-flatten',os.path.join(outImages, fileName)] convp=subprocess.call(convargs) elif(extension <> '.pdf'): shutil.copy(os.path.join(inImages, imageFile), os.path.join(outImages, imageFile)) if(extension == '.pdf' and getPdf): shutil.copy(os.path.join(inImages, imageFile), os.path.join(outImages, imageFile)) index.write(''' ''') if input_menuChoices==None: noChoices() else: withChoices()