There are two places where resolution can potentially be saved (i.e., the JPEG resolution for printing, also referred to in abbreviated form as DPI or dots per inch).
The first is in the JFIF JPEG header, which is often (but NOT always) right at the beginning of the JPEG.
The other is in EXIF data.
, , , . . , . , JPEG (,), .
, JFIF, , APP0, . ( SOI.):
function read_JFIF_dpi($filename)
{
$dpi = 0;
$fp = @fopen($filename, r);
if ($fp) {
if (fseek($fp, 6) == 0) {
if (($bytes = fread($fp, 16)) !== false) {
if (substr($bytes, 0, 4) == "JFIF") {
$JFIF_density_unit = ord($bytes[7]);
$JFIF_X_density = ord($bytes[8])*256 + ord($bytes[9]);
$JFIF_Y_density = ord($bytes[10])*256 + ord($bytes[11]);
if ($JFIF_X_density == $JFIF_Y_density) {
if ($JFIF_density_unit == 1) $dpi = $JFIF_X_density;
else if ($JFIF_density_unit == 2) $dpi = $JFIF_X_density * 2.54;
}
}
}
}
fclose($fp);
}
return ($dpi);
}