No BSD License  

Highlights from
Get Resolution

from Get Resolution by Asaf
The function finds the resolution of jpeg or tif file.

[xRes,yRes] =getresolution(file_name)
function [xRes,yRes] =getresolution(file_name)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   The function finds the resolution of the picture
%   it can handle 'jpg' and 'tif' formats
%   the information of the resolution in the 'jpg' file
%   is stored in the 15-16th and in the 17-18th bytes.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

info=imfinfo(file_name);
if info.Format=='jpg'
    [xRes,yRes]=getjpegresolution(file_name);
else if info.Format=='tif'
        [xRes,yRes]=gettifresolution(info);
    end
end

function [xRes,yRes] = getjpegresolution(file)
fid=fopen(file);
header=fread(fid,50);
xRes=(header(15)*256)+header(16);
yRes=(header(17)*256)+header(18);
fclose(fid);

function [xRes,yRes] = gettifresolution(info)
xRes=info.XResolution;
yRes=info.YResolution;

Contact us at files@mathworks.com