# # function write_html_image_list(filename,imageFilenames,titles, options) # # Given a list of image file names, writes an HTML file that # shows all those images, with optional one-line headers above each. # # Each "filename" can also be a list array of filenames (they will share a title). # # Strips directory information away if options.makeRelative == 1. # # Tries to convert absolute to relative paths if options.makeRelative == 2. # # Owner: Dan Morris (dan@microsoft.com) # #%% Constants and imports import math import matlab_porting_tools as mpt #%% write_html_image_list def write_html_image_list(filename=None,imageFilenames=None,titles=(),options={}): # returns an options struct if 'fHtml' not in options: options['fHtml'] = -1 if 'makeRelative' not in options: options['makeRelative'] = 0 if 'headerHtml' not in options: options['headerHtml'] = '' if 'trailerHtml' not in options: options['trailerHtml'] = '' if 'imageStyle' not in options: options['imageStyle'] = '' # Possibly split the html output for figures into multiple files; Chrome gets sad with # thousands of images in a single tab. if 'maxFiguresPerHtmlFile' not in options: options['maxFiguresPerHtmlFile'] = math.inf if filename == None: return options # Remove leading directory information from filenames if requested if options['makeRelative'] == 1: for iImage in range(0,len(imageFilenames)): _,n,e = mpt.fileparts(imageFilenames[iImage]) imageFilenames[iImage] = n + e elif options['makeRelative'] == 2: baseDir,_,_ = mpt.fileparts(filename) if len(baseDir) > 1 and baseDir[-1] != '\\': baseDir = baseDir + '\\' for iImage in range(0,len(imageFilenames)): fn = imageFilenames[iImage] fn = fn.replace(baseDir,'') imageFilenames[iImage] = fn nImages = len(imageFilenames) if len(titles) != 0: assert len(titles) == nImages,'Title/image list mismatch' # If we need to break this up into multiple files... if nImages > options['maxFiguresPerHtmlFile']: # You can't supply your own file handle in this case if options['fHtml'] != -1: raise ValueError( 'You can''t supply your own file handle if we have to page the image set') figureFileStartingIndices = list(range(0,nImages,options['maxFiguresPerHtmlFile'])) assert len(figureFileStartingIndices) > 1 # Open the meta-output file fMeta = open(filename,'w') # Write header stuff fMeta.write('
\n') fMeta.write(options['headerHtml']) fMeta.write('\n')
fMeta.write(' ') fMeta.write('Figures for images {} through {} |
{}
\n'\ .format(s)) # If we have multiple images for this same title if (isinstance(imageFilenames[iImage],list)): files = imageFilenames[iImage]; for iFile in range(0,len(files)): fHtml.write('