% image2html - Convert a color image into color text art in html % % Usage: % color_all=image2html(im,string,text,pixel,filename) % % % Arguments: % im - input color image % string - the character strings to be used % text - Page header % pixel - the number of characters per line in the output % filename - the output filename % % Output: % color_all - resized image pixel value in HEX (255=FF) % 4-D : 2-D image * 3 components (RGB) * 2 chars (HEX) % % Example: % >> im=imread('down.bmp'); % >> color_all=image2html(im,'DOWN','going down',80,'down.html'); % % % Author: % Tzu Yen Wong % wongt AT csse DOT uwa DOT edu DOT au % Department of Computer Science & Software Engineering % The University of Western Australia % July 2003 % Added comments: Oct 2003 function color_all=image2html(im,string,text,pixel,filename) if nargin < 2, string ='HTM'; text = string; pixel = 120; filename = sprintf('%s.html',string); elseif nargin <3, text = string; pixel = 120; filename = sprintf('%s.html',string); elseif nargin <4, pixel = 120; filename = sprintf('%s.html',string); elseif nargin <5, filename = sprintf('%s.html',string); end if isempty(findstr(filename,'htm')), filename = sprintf('%s.html',filename); end % Fine tuning variables: pagetitle =text; bgcolor = 'black'; %lineheight = '40'; %fontsize = '5.0pt'; %fontfamily = 'sans-serif'; %letterspacing = '1.3pt'; %lineheight = '40'; %fontsize = '5.0pt'; %fontfamily = 'terminal'; %letterspacing = '2.0pt'; lineheight = '45'; fontsize = '5.0pt'; fontfamily = 'Lucida Console'; letterspacing = '1.5pt'; titlefontsize = '12.0pt'; titlefontfamily = 'sans-serif'; titlecolor = 'red'; footercolor = '#404040'; disp(sprintf('File : %s generated in %s',filename, pwd)); fid = fopen(filename,'w'); fprintf(fid,'\n'); fprintf(fid,'%s%s, %s %s%s\n',... ' '); fprintf(fid,'\n \n'); fprintf(fid,' %s\n',pagetitle); fprintf(fid,'\n\n',bgcolor); fprintf(fid,'

\n',lineheight); fprintf(fid,... '\n',... fontsize,fontfamily,letterspacing); fprintf(fid,... '%s%s\n',... titlefontsize,titlefontfamily,titlecolor,text,... '





'); [row,col,d]=size(im); if row>pixel || col>pixel, a = row/pixel; b = col/pixel; ratio=max(a,b) row=round(row/ratio); col=round(col/ratio); im=imresize(im,[row,col],'bicubic'); % show(im) end im = uint8(round(double(im)/8)*8); % may be used to reduce file size color_all = dec2hex(double(im)); color_all = reshape(color_all,row,col,d,2); color_all(row,col+1,d,:)='ZZ'; str_l = length(string); samecolor=0; for row_i =1:row, str_i = 1; for col_i=1:col, % next pixel has the same color = YES if color_all(row_i,col_i,:)==color_all(row_i,col_i+1,:), % previous pixel has the same color = NO if samecolor==0, if ndims(im)<3, % Black & White image fprintf(fid,'%s',... color_all(row_i,col_i,:),color_all(row_i,col_i,:),... color_all(row_i,col_i,:),string(str_i)); else % Color image fprintf(fid,'%s',... color_all(row_i,col_i,1,:),... color_all(row_i,col_i,2,:),... color_all(row_i,col_i,3,:),string(str_i)); end % previous pixel has the same color = YES else fprintf(fid,'%s',string(str_i)); end samecolor = 1; % next pixel has the same color = NO else % previous pixel has the same color = NO if samecolor==0, if ndims(im)<3, fprintf(fid,'%s',... color_all(row_i,col_i,:),color_all(row_i,col_i,:),... color_all(row_i,col_i,:),string(str_i)); else fprintf(fid,'%s',... color_all(row_i,col_i,1,:),... color_all(row_i,col_i,2,:),... color_all(row_i,col_i,3,:),string(str_i)); end % previous pixel has the same color = YES else fprintf(fid,'%s',string(str_i)); end samecolor = 0; end if str_i < str_l, str_i = str_i + 1; else str_i = 1; end end fprintf(fid,'
\n'); % fprintf(fid,'
'); end fprintf(fid,'

\n'); %1234567890123456789012345678901234567890123456789012345678901234567890123456789 fprintf(fid,'

'); fprintf(fid,'Generated on %s using image2html.m ',... footercolor,datestr(now,31)); fprintf(fid,'%s%s%s\n',... '
code by ',... '',... 'WTY

'); fprintf(fid,'

'); fprintf(fid,'\n\n'); fclose(fid);