% This program reads images from the folder specified % by the 'folder' variable, renames them from the defaults, % creates thumbnail versions and places them into a webpage % format. % % It is HIGHLY recommended that the user make a copy of the % original files before running this program incase the % originals are lost or damaged. % % Program usage: If it is desireed to change the image % file names from the default to a generic name, i.e. % 'GrandCanyon1.jpg', 'GrandCanyon2.jpg', etc, the % 'rename' routine can be used. % % To create a webpage of clickable thumbnail images, % the 'resize' routine must be used first to shrink the % images. % % Use the 'webpage' routine to create the html webpage. % % Last edited by Colin Joye, 8/10/02 % % run webpic clear all; tic; %--- User constants ------------ % % Basics: (must include the ending '\' after path) folder = 'c:\documents and settings\colin joye\desktop\test\'; type = 'jpg'; % jpg, gif, bmp, tiff, etc. % % Rename from defaults to 'name_x.jpg'. rename = 1; % '1' to run "rename". name = 'korea_'; % % Resize: '1' to resize all images in the folder. resize = 1; stepsize = 10; % retains every 10th pixel. % % Webpage: '1' to auto-generate a webpage of clickable thumbnails. webpage = 1; webfile = 'korea.html'; % name of webpage. title = 'Korea, 5/03 - 6/03'; % Puts title into webpage. %------------------------------- % ---------- Rename function -------------------------- if rename==1, files = dir(folder); [f,n] = sortrows(str2mat(files.name)); % Puts files in order. Lf = length(files); Lt = length(type); F = cellstr(f); % Turns sorted files into a cell array. h = waitbar(0,'Renaming image files'); for k=1:Lf, c = [folder files(n(k)).name]; % current file path & name. if exist(c)~=7, % ignores directories. if k<12, % prepends zero if < 10. z='0'; else z=''; end new = [name z num2str(k-2) '.' type]; % new file path & name. if any(strcmp(F,new)), % Prevents overwriting existing files. disp(['RENAME: File Already Exists: ''' new '''']); disp(['Exitting "rename". ' num2str((k-3)/Lf) ... ' % Complete. Delete renamed files and try again.']); break; end Lc = length(c); try, A = imread(c); % Reads current image. imwrite(A,[folder new], type); % Writes new name. if exist(c)==2, s=['delete' ' ''' c ''' ']; eval(s); end catch, disp(['Warning (RENAME): ''' c ''' could not be "read".']); end waitbar((k-1)/Lf,h); end end close(h); end % ---------- Resize function -------------------------- if resize==1, files = dir(folder); [f,n] = sortrows(str2mat(files.name)); % Puts files in order. Lf = length(files); Lt = length(type); h = waitbar(0,'Resizing image files'); for k=3:Lf, c = [folder files(k).name]; % current file path & name. if exist(c)~=7, % ignores directories. Lc = length(c); try, A = imread(c, type ); % Reads current image. x = 1:stepsize:size(A,1); y = 1:stepsize:size(A,2); B = A(x,y,:); % samples image to shrink it. s = c( 1:(Lc-Lt-1) ); % file name string. e = c( (Lc-Lt):end ); % file extension string. imwrite(B,[s '_' e]); catch, disp(['Warning (RESIZE): ''' c ''' could not be "read".']); end waitbar(k/Lf,h); end end close(h); end % ---------- Webpage function -------------------------- if webpage==1, files = dir(folder); [f,n] = sortrows(str2mat(files.name)); % Puts files in order. Lf = length(files); Lt = length(type); file = [folder webfile]; if exist(file)==2, %exist=2 is a file. s=['delete' ' ''' file ''' ']; eval(s); end w = fopen(file,'w'); h = ['
']; td = [td d ' | '];
if mod(cnt,5)==0, % Breaks table into rows.
td = [td '