Code covered by the BSD License  

Highlights from
HTML Indexer

image thumbnail

HTML Indexer

by

 

16 Aug 2004 (Updated )

automated multi-language html index, index for print, batch image scaling

GenerateHtml(FileList,Dir,Options)
function GenerateHtml(FileList,Dir,Options)
% 02.07.2011    - revisit tables, centering, etc.
%               - add prev/next thumbnails L/R, easy navigation
%               - GenerateGallery now a subfunction

if nargin < 3
    Options=uConstr('options'); 
    disp(' GenerateHtml > missing options, using defaults'); 
end

% convert Options.FontSize from a number into an html meaningful string
% ---------------------------------------------------------------------
FontSize_HtmlStr = '';
font_stop = '</font>';
if Options.FontSize ~= 0
    if (Options.FontSize > 0) && (Options.FontSize < 5) % asssuming relative, "+1", etc
        FontSize_HtmlStr  = ['<font size = +'  num2str(Options.FontSize) '>'];
    else % negative relative or true (positive) font size
        FontSize_HtmlStr  = num2str(Options.FontSize); % -1, -2, 10, etc
    end
    FontSize_HtmlStr  = ['<font size = ' FontSize_HtmlStr '>'];
    font_stop = ['</font>' font_stop];
end

% --- vezi la ce rezolutie esti
switch Options.activeresolution
    case 'high' % later
    case 'normal'
        font_start = ['<font face="' Options.FontFace '">' FontSize_HtmlStr ];
        % font_start = ['<font face="' Options.FontFace '"><font size=' num2str(Options.FontSize) '>'];
        img_size_conv_factor = 1;
        suffix_res = '';
    case 'low'
        font_start = ['<font face="' Options.FontFace '"><font size=' num2str(Options.FontSize-1) '> '];
        img_size_conv_factor = Options.ThSize/Options.ThSizeLow;
        suffix_res = '_lo';
end

for ix_lang=1:size(Options.languages,1)
    suffix_lang = '';
    if ix_lang > 1
        suffix_lang = ['_' deblank(Options.languages(ix_lang,:))];
    end
    IndexName = fullfile(Dir.Dest, ['index' suffix_lang suffix_res '.html']);
    fh = fopen(IndexName, 'wt');
    
    % --- scrie in .html ... balariile de la inceput
    fprintf(fh, '%s\n%s\n', '<html>', '<head>');
    fprintf(fh, '%s\n', '    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">');
    fprintf(fh, '\n%s', '    <meta name="Author" content="');
    fprintf(fh, '%s', [Options.Autor '">']);
    fprintf(fh, '\n%s', '    <meta name="GENERATOR" content="Quadra">');
    fprintf(fh, '\n%s', ['    <title>' Options.Titlu(ix_lang,:) '</title>']);
    fprintf(fh, '\n%s', '</head>');
    fprintf(fh, '\n%s\n', ['<body text="#' Options.Colour.text '" bgcolor="#' Options.Colour.bg '" link="#' Options.Colour.link '" vlink="#' Options.Colour.vlink '" alink="#' Options.Colour.alink '">']);
    
    fprintf(fh, '\n%s\n', ['<center>' font_start deblank(Options.TextSus(ix_lang,:)) font_stop '</center>']);
    
    % --- partea de change language ---
    if size(Options.languages,1)>1
        fprintf(fh, '\n%s\n', ['<left><br> ' Options.TextLang(ix_lang,:) '</left>']);
        for ix_link=1:size(Options.languages,1)
            suffix_link = '';  if ix_link > 1 suffix_link = ['_' deblank(Options.languages(ix_link,:))]; end;
            suffix_display = deblank(Options.languages(ix_link,:));
            if ix_link ~= ix_lang 
                fprintf(fh, '\n%s\n', [' .> <a href="index' suffix_link '.html"> ' suffix_display '</a>' ]);
            end;
        end;
    end;
    fprintf(fh, '\n%s', '<br>');
    % --- aici incep pozele ---
    if sum(strcmp(Options.prjtype,{'net', 'contact'}))
        for ix_file=1:size(FileList,2)
            h_word = num2str(fix(FileList(ix_file).th_height/img_size_conv_factor));
            w_word = num2str(fix(FileList(ix_file).th_width/img_size_conv_factor));  
            fprintf(fh, '\n%s', [ '<a href="' FileList(ix_file).base suffix_lang suffix_res '_gy.html">']);
            fprintf(fh, '\n%s\n', [ '<img SRC="' FileList(ix_file).base '_th.jpg" ALT="' deblank(FileList(ix_file).TextOver(ix_lang,:)) '"HSPACE=1 VSPACE=1 BORDER=0 height=' h_word ' width=' w_word ' align=ABSCENTER></a>']);
            % --- aici generezi si un fisier *_gy.html
            GenerateGallery(FileList, Dir, Options,ix_lang);
        end
    else % adica 'local', pointeaza direct spre sursa la dimensiunea originala
        for ix_file=1:size(FileList,2)
            fprintf(fh, '\n%s', [ '<a href="' FileList(ix_file).base'.' FileList(ix_file).extension '">']);
            fprintf(fh, '\n%s\n', [ '<img SRC="' FileList(ix_file).base '_th.jpg" ALT="' deblank(FileList(ix_file).TextOver(ix_lang,:)) '"HSPACE=1 VSPACE=1 BORDER=0 height=' num2str(FileList(ix_file).th_height) ' width=' num2str(FileList(ix_file).th_width) ' align=ABSCENTER></a>']);
            % aici generezi si un fisier *_gy.html in care chemi fisieru
            % original la dimeniunea dorita in Options
            % sau nimic ! GenerateGallery(FileList, Dir, Options,i);
        end;
    end;
    % --- home link
    fprintf(fh, '\n%s', [ '<br>' font_start '<a href="' ...
        deblank(Options.LinkHome(ix_lang,:)) '"> ' ...
        deblank(Options.TextHome(ix_lang,:)) '</a>' font_stop]);
    % --- text DOWN tagurile ---
    fprintf(fh, '\n\n%s', ['<br> <center>' font_start Options.TextJos(ix_lang,:) font_stop '</center>']);
    % --- close tags ---
    fprintf(fh, '\n%s%s', '</body>','</html>');
    fclose(fh);
    fprintf(1,'\n%s', ['... html index done (' suffix_lang ' ' Options.activeresolution ' res)']);
end; % for languages

end

function GenerateGallery(FileList,Dir,Options,ix_lang)

% genereaza toate fisierele _gy pentru limba ix_lang
% v.0.41, 9-10 nov.2003
% v.0.45, 13.12.2003, schimbat layoutu' galeriei
% 02.07.2011    - v.0.5.3, update table alignment, 
%                 add thumbnails L/R for prev/next

% --- vezi ce limba faci
suffix_lang = '';
if ix_lang > 1
    suffix_lang = ['_' deblank(Options.languages(ix_lang,:))];
end

% convert Options.FontSize from a number into an html meaningful string
FontSize_HtmlStr = '';
font_stop = '</font>';
if Options.FontSize ~= 0
    if (Options.FontSize > 0) && (Options.FontSize < 5) % asssuming relative, "+1", etc
        FontSize_HtmlStr  = ['<font size = +'  num2str(Options.FontSize) '>'];
    else % negative relative or true (positive) font size
        FontSize_HtmlStr  = num2str(Options.FontSize); % -1, -2, 10, etc
    end
    FontSize_HtmlStr  = ['<font size = ' FontSize_HtmlStr '>'];
    font_stop = ['</font>' font_stop];
end
% --- si la ce rezolutie esti
switch Options.activeresolution
    case 'high' % later
    case 'normal'
        font_start = ['<font face="' Options.FontFace '">' FontSize_HtmlStr ];
        img_size_conv_factor = 1;
        suffix_res = '';
    case 'low'
        font_start = ['<font face="' Options.FontFace '"><font size=' num2str(Options.FontSize-1) '> '];
        img_size_conv_factor = Options.GySize/Options.GySizeLow;
        suffix_res = '_lo';
end

for ix_file = 1:size(FileList,2)
    fname = fullfile(Dir.Dest , [FileList(ix_file).base suffix_lang suffix_res '_gy.html']);
    fg = fopen(fname, 'wt');
    
    % --- scrie in .html ... balariile de la inceput
    fprintf(fg, '%s\n%s\n', '<html>', '<head>');
    fprintf(fg, '%s\n', '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">');
    fprintf(fg, '\n%s', '    <meta name="Author" content="');
    fprintf(fg, '%s', [Options.Autor '">']);
    fprintf(fg, '\n%s', '    <meta name="GENERATOR" content="Quadra">');
    fprintf(fg, '\n%s', ['    <title>' Options.Titlu(ix_lang,:) '</title>']);
    fprintf(fg, '\n%s', '</head>');
    fprintf(fg, '\n%s\n', ['<body text="#' Options.Colour.text '" bgcolor="#' Options.Colour.bg '" link="#' Options.Colour.link '" vlink="#' Options.Colour.vlink '" alink="#' Options.Colour.alink '">']);
    
    % -titlu-
    %fprintf(fg, '\n%s\n', [font_start Options.Titlu(ix_lang,:) font_stop ' <br> ']);
    % -up-
    fprintf(fg, '\n%s', [font_start '<a href="index' suffix_lang suffix_res '.html"> up one level ...</a> ' font_stop]);
    
    % -vezi in alte limbi-
    for ix_link=1:size(Options.languages,1)
        if ix_link ~= ix_lang
            suffix_link = '';  
            if ix_link > 1
                suffix_link = ['_' deblank(Options.languages(ix_link,:))]; 
            end
            suffix_display = deblank(Options.languages(ix_link,:));
            % if ix_link > 1 suffix_lang_link = ['_' deblank(Options.languages(ix_lang,:))]; else suffix_lang_link = ''; end;
            target_file_name = [FileList(ix_file).base suffix_link suffix_res '_gy.html'];
            fprintf(fg, '%s', [font_start deblank(Options.TextLang(ix_link,:)) ' .> <a href="' target_file_name '"> ' suffix_display '</a> ... ' font_start ]);
        end;
    end;
    
    %StrTableHeader_old = '<table BORDER=0 COLS=3 WIDTH="100%" >';
    StrTableHeader = '<TABLE WIDTH="900" ALIGN="CENTER" BORDER=0>';
    fprintf(fg, '\n%s\n', StrTableHeader);
    TopTextCell = {'', '', ''};
    PicTextCell = {'', '', ''};
    
    % - PREVIOUS -
    % ------------
    if ix_file > 1
        LinkPrevFile = [FileList(ix_file-1).base suffix_lang ...
            suffix_res '_gy.html'];
        wtdStr = [font_start '<a href="' LinkPrevFile '"> previous</a> ' font_stop];
        %fprintf(fg, '\n%s', wtdStr);
        TopTextCell{1} = wtdStr;
        % figure out size of 'prev' thumbnail
        h_word = num2str(fix(FileList(ix_file-1).th_height/img_size_conv_factor));
        w_word = num2str(fix(FileList(ix_file-1).th_width/img_size_conv_factor));
        PrevFileThName = [FileList(ix_file-1).base '_th.jpg' ]; % FileList(ix_file-1).extension
        
        PicTextCell{1} = ['<a href=" ' LinkPrevFile '"> <img SRC="' PrevFileThName ...
            '" ALT="placeholder" HSPACE=1 VSPACE=1 BORDER=0 ' ...
            ' height=' h_word ' width=' w_word ...
            ' align=ABSCENTER></a>'];
    end
  
    % - LEGEND -
    % ----------
    wtdStr = [font_start  num2str(ix_file) '/' ...
        num2str(size(FileList,2)) ' > ' ...
        deblank(FileList(ix_file).Legenda(ix_lang,:)) font_stop];
    TopTextCell{2} = wtdStr;
    
    % -   NEXT   -
    % ------------
    if ix_file<size(FileList,2)
        LinkedFile = [FileList(ix_file+1).base ...
            suffix_lang suffix_res '_gy.html'];
        wtdStr = [font_start ' <a href="' LinkedFile '"> next</a>' font_stop];

        TopTextCell{3} = wtdStr;
        
        % figure out size of 'next' thumbnail
        h_word = num2str(fix(FileList(ix_file+1).th_height/img_size_conv_factor));
        w_word = num2str(fix(FileList(ix_file+1).th_width/img_size_conv_factor));
        NextFileThName = [FileList(ix_file+1).base '_th.jpg']; %  FileList(ix_file+1).extension
        
        PicTextCell{3} = ['<a href=" ' LinkedFile '"> <img SRC="' NextFileThName ...
            '" ALT="placeholder" HSPACE=1 VSPACE=1 BORDER=0 ' ...
            ' height=' h_word ' width=' w_word ...
            ' align=ABSCENTER></a>'];
    end

    % --- main PICTURE link ---
    h_word = num2str(fix(FileList(ix_file).gy_height/img_size_conv_factor));
    w_word = num2str(fix(FileList(ix_file).gy_width/img_size_conv_factor));
    PicTextCell{2} = [ '<img SRC="' FileList(ix_file).base ...
        '_gy.jpg" ALT="' deblank(FileList(ix_file).TextOver(ix_lang,:)) ...
        '"HSPACE=1 VSPACE=1 BORDER=0 height=' h_word ' width=' w_word ...
        ' align=ABSCENTER></a>'];

    % --- write to .html file ---
    % write the top table row
    WriteTableRow(fg, TopTextCell)
    % write the 2nd row, Prev/Next Thumbs, Main Img
    WriteTableRow(fg, PicTextCell)

    % write TABLE END, file end
    signatureStr = ['<br> <center>' font_start 'HTML indexer 0.6' font_stop '</center>'];
    fprintf(fg, '\n%s\n%s', '</TABLE>', signatureStr, '<br></body> </html>' );
    
fclose(fg);
end
end

function WriteTableRow(fg, TextCell)
fprintf(fg, '\n%s', '<TR>');
% TextCell is 3 long
fprintf(fg, '\n%s%s%s', ...
    '  <TD ALIGN="RIGHT" VALIGN="MIDDLE">', ...
    TextCell{1}, ' </TD>');
fprintf(fg, '\n%s%s%s', ...
    '  <TD ALIGN="CENTER" VALIGN="MIDDLE">', ...
    TextCell{2}, ' </TD>');
fprintf(fg, '\n%s%s%s', ...
    '  <TD ALIGN="LEFT" VALIGN="MIDDLE">', ...
    TextCell{3}, ' </TD>');
fprintf(fg, '\n%s', '</TR>');
end

Contact us