mf_settings;

[SLM] = imread( 'Streamlines_eps.png');

% streamlines image size
[hl,wl, clrs] = size(SLM);

clear SLM;

% svg size, as set in makelegend
wrs = 150;
hls = 80 + 40*length( imagevaluesused);


wr = round(wl*wrs/hls);
hr = hl;

% density = 1*72* wl/wrs;
% 
% commandstr = sprintf( 'convert -density %f legend.svg legend.png', density);

% if makenewlegend,


if exist( 'legend2.svg', 'file'),
    legendtouse = 'legend2.svg';
else
    makelegend2( 'legend.svg');
    legendtouse = 'legend.svg';
end
% end

zoom = hl/hls;
commandstr = sprintf( 'rsvg-convert %s -x %f -y %f -o legend.png', legendtouse, zoom, zoom );



system( commandstr );
commandstr = sprintf( 'montage -gravity west -geometry "%ix%i>+4+4" Streamlines_eps.png legend.png merged.png', wl+2, hl+2 );
system( commandstr );


[MERGED] = imread('merged.png');
findlastblackpixel = find(~all(MERGED(:,:,3)));

clear MERGED

lastblackpixel = findlastblackpixel(end);

commandstr = sprintf( 'convert -crop "%ix%i+0+0" merged.png merged_cropped.png', [lastblackpixel+25, hl]);
system( commandstr );

if altavailable,
    commandstr = sprintf( 'montage -gravity west -geometry "%ix%i>+4+4" AlterationStreamlines_eps.png legend.png Alt_merged.png', wl+2, hl+2 );
    system( commandstr );

    commandstr = sprintf( 'convert -crop "%ix%i+0+0" Alt_merged.png Alt_merged_cropped.png', [lastblackpixel+25, hl]);
    system( commandstr );
end