Changeset 2816


Ignore:
Timestamp:
01/13/10 12:00:51 (15 years ago)
Author:
Eric.Larour
Message:

Improved option driven printmodel

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/m/classes/public/printmodel.m

    r2746 r2816  
    1 function printmodel(filename,format)
     1function printmodel(filename,format,varargin)
    22%PRINTMODEL - save an image of current figure
    33%
    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')
    56%
     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%   
    619%   Usage:
    7 %      printmodel(filename,format)
     20%      printmodel('image','tiff')
    821
    9 %Get current figure
    10 fig=gcf;
     22
     23%get options:
     24options=pairoptions(varargin{:});
     25
     26%set defaults
     27options=addfielddefault(options,'figure','gcf');
     28options=addfielddefault(options,'format','tiff');
     29options=addfielddefault(options,'resolution',2);
     30options=addfielddefault(options,'margin','on');
     31options=addfielddefault(options,'marginsize',5);
     32options=addfielddefault(options,'frame','on');
     33options=addfielddefault(options,'framesize',5);
     34options=addfielddefault(options,'framecolor','black');
     35options=addfielddefault(options,'trim','off');
     36options=addfielddefault(options,'hardcopy','on');
     37
     38%get fig:
     39fig=getfieldvalue(options,'figure');
     40if ischar(fig),
     41        fig=gcf;
     42else
     43        figure(fig);
     44        fig=gcf;
     45end
    1146
    1247%In auto mode, MATLAB prints the figure the same size as it appears on the computer screen, centered on the page
     
    1449
    1550%InvertHardcopy off imposes MATLAB to use the same colors
    16 set(fig, 'InvertHardcopy', 'off');
     51set(fig, 'InvertHardcopy', getfieldvalue(options,'hardcopy'));
    1752
    1853%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);
     54print(fig, '-zbuffer','-dtiff',['-r' num2str(get(0,'ScreenPixelsPerInch')*getfieldvalue(options,'resolution'))],filename);
    2055
    21 %Add frame except if pdf
     56%some trimming involved?
     57if strcmpi(getfieldvalue(options,'trim'),'on'),
     58        eval(['!convert -trim ' filename '.tif ' filename '.tif']);
     59end
     60
     61%margin?
     62if 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']);
     65end
     66
     67%frame?
    2268if ~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
    2474end
     75
     76%convert image to correct format
     77if ~strcmpi(format,'tiff'),
     78        eval(['!convert ' filename '.tif ' filename '.' format]);
     79end
Note: See TracChangeset for help on using the changeset viewer.