function replace_png_by_jpg(htmlfile)
% REPLACE_PNG_BY_JPG does exchange the .png string by .jpg
%
% These is usefull, if you want to use another Screenshots in your
% published HTML-File with the extention JPG instead of selected default
% PNG.
%
% Syntax: >> replace_png_by_jpg('HTML_File')
%
% See Also: NEWFCN_RENAME PUBLISH_TECHNICS
%% AUTHOR : Frank Gonzalez-Morphy
%% $DATE : 28-Jul-2004 18:00:35 $
%% $Revision : 1.00 $
%% DEVELOPED : 7.0.0.19920 (R14)
%% FILENAME : replace_png_by_jpg.m
if nargin == 0, help(mfilename); return, end
ext_htmlfile = '.html'; % default extension
s = strfind(htmlfile,ext_htmlfile); % does have input .html extension ?
if isempty(s)
htmlfile_ext = [htmlfile ext_htmlfile]; % complete filename
else
htmlfile_ext = htmlfile; % filename with extension
end
dir_pwd = pwd; % remember actual directory
if exist(htmlfile_ext) == 0 % not in current directory
mfile = htmlfile_ext(1,1:end-5); % search for M-File ~ publish
w = which(mfile); % saving place of M-File
if isempty(w) % M-File not known in ML Path
error([' MSG: M-File ' , mfile , ' couldn''t be found!'])
end
[pathstr,name,ext,versn] = fileparts(w); % otherwise separate fileparts
cd([pathstr '\html']) % if published HTML file
if exist(htmlfile_ext) == 0 % does exist ? if yes, go further
cd(dir_pwd) % if error happens, back to workdir
error([' MSG: HTML File ' , htmlfile_ext , ' doesn''t exist or couldn''t found!'])
end
end
% Open source File for Reading content
fid = fopen(htmlfile_ext, 'r');
% ... scan the Text content ...
Scaned_Text = fscanf(fid, '%c', inf);
% ... Close the File.
fclose(fid);
% Extensions
jpg_str = '.jpg"';
png_str = '.png"';
% Sizes of the Extensions
sz_jpg = size(jpg_str,2);
sz_png = size(png_str,2);
% Position of extention PNG in scaned Text
Start_Pos_png = findstr(png_str, Scaned_Text);
% Renaming Scaned Text with another Extention: JPG
Modified_Text = [Scaned_Text(1,1:Start_Pos_png-1) jpg_str, ...
Scaned_Text(1,Start_Pos_png+sz_jpg:end)];
% Open File for Writing modified content discarting original content
fid = fopen(htmlfile_ext, 'w');
% ... write the modified content
fprintf(fid, '%s', Modified_Text);
% ... and close the File
st = fclose(fid);
if st == 0 % done well ? yes, go further
disp([' MSG: In <' htmlfile_ext '> .png replaced by .jpg !'])
% NOTE: Open file in MATLAB Editor / Debugger, if already opened it
% should be automatically updated ! BUG = these doesn't happen if
% Editor window of file content is highlighted. First changing forward
% and backward the content will be reloaded and updated.
edit(htmlfile_ext); % Edit the modified File on the Editor
cd(dir_pwd) % return to started directory
end
% Created with NEWFCN.m by Frank Gonzlez-Morphy
% Contact...: frank.gonzalez-morphy@mathworks.de
% ===== EOF ====== [replace_png_by_jpg.m] ======