Changeset 2816
- Timestamp:
- 01/13/10 12:00:51 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/m/classes/public/printmodel.m
r2746 r2816 1 function printmodel(filename,format )1 function printmodel(filename,format,varargin) 2 2 %PRINTMODEL - save an image of current figure 3 3 % 4 % the format is the same as the one accepted by the builtin imwrite routine. 4 % filename: output name of image file (no extension) 5 % format: image format (ex: 'tiff','jpg','pdf') 5 6 % 7 % List of options to printfmodel: 8 % 9 % figure: number of figure to print (default: current figure) 10 % resolution: use higher resolution to anti-alias (default 2) 11 % margin: add margin around final image 12 % marginsize: size of margin around final image (default 5) 13 % frame: add frame around final image 14 % framesize: size of frame around final image (default 5) 15 % framecolor: color of frame around final image (default 'black') 16 % trim: trim empty space around image (default 'off') 17 % hardcopy: 'off' to impose MATLAB to use the same colors (default 'on') 18 % 6 19 % Usage: 7 % printmodel( filename,format)20 % printmodel('image','tiff') 8 21 9 %Get current figure 10 fig=gcf; 22 23 %get options: 24 options=pairoptions(varargin{:}); 25 26 %set defaults 27 options=addfielddefault(options,'figure','gcf'); 28 options=addfielddefault(options,'format','tiff'); 29 options=addfielddefault(options,'resolution',2); 30 options=addfielddefault(options,'margin','on'); 31 options=addfielddefault(options,'marginsize',5); 32 options=addfielddefault(options,'frame','on'); 33 options=addfielddefault(options,'framesize',5); 34 options=addfielddefault(options,'framecolor','black'); 35 options=addfielddefault(options,'trim','off'); 36 options=addfielddefault(options,'hardcopy','on'); 37 38 %get fig: 39 fig=getfieldvalue(options,'figure'); 40 if ischar(fig), 41 fig=gcf; 42 else 43 figure(fig); 44 fig=gcf; 45 end 11 46 12 47 %In auto mode, MATLAB prints the figure the same size as it appears on the computer screen, centered on the page … … 14 49 15 50 %InvertHardcopy off imposes MATLAB to use the same colors 16 set(fig, 'InvertHardcopy', 'off');51 set(fig, 'InvertHardcopy', getfieldvalue(options,'hardcopy')); 17 52 18 53 %Use higher resolution to anti-alias and use zbuffer to have smooth colors 19 print(fig, '-zbuffer', ['-r' num2str(get(0,'ScreenPixelsPerInch')*2)], ['-d' format],filename);54 print(fig, '-zbuffer','-dtiff',['-r' num2str(get(0,'ScreenPixelsPerInch')*getfieldvalue(options,'resolution'))],filename); 20 55 21 %Add frame except if pdf 56 %some trimming involved? 57 if strcmpi(getfieldvalue(options,'trim'),'on'), 58 eval(['!convert -trim ' filename '.tif ' filename '.tif']); 59 end 60 61 %margin? 62 if strcmpi(getfieldvalue(options,'margin'),'on'), 63 marginsize=getfieldvalue(options,'marginsize'); 64 eval(['!convert -border ' num2str(marginsize) 'x' num2str(marginsize) ' -bordercolor "white" ' filename '.tif ' filename '.tif']); 65 end 66 67 %frame? 22 68 if ~strcmpi(format,'pdf'), 23 system(['convert -border 5x5 -bordercolor "#000000" ' filename ' ' filename ]); 69 if strcmpi(getfieldvalue(options,'frame'),'on'), 70 framesize=getfieldvalue(options,'framesize'); 71 framecolor=getfieldvalue(options,'framecolor'); 72 eval(['!convert -border ' num2str(framesize) 'x' num2str(framesize) ' -bordercolor "' framecolor '" ' filename '.tif ' filename '.tif']); 73 end 24 74 end 75 76 %convert image to correct format 77 if ~strcmpi(format,'tiff'), 78 eval(['!convert ' filename '.tif ' filename '.' format]); 79 end
Note:
See TracChangeset
for help on using the changeset viewer.