Intervention/image · info · AnalyzerException
Unable to read JFIF header
Error message
Unable to read JFIF header
What it means
The first recovery strategy for JPEG resolution reads the first 20 bytes of the origin file and looks for the literal 'JFIF' segment marker. If strpos() cannot find it, this AnalyzerException is thrown and the caller falls through to the EXIF parser. It is an internal stepping stone: readResolutionFromOrigin() catches it, and analyze() ultimately swallows everything, so it never surfaces through the public API.
Source
Thrown at src/Drivers/Gd/Analyzers/ResolutionAnalyzer.php:115
fclose($handle);
}
}
/**
* @param resource $handle
* @throws AnalyzerException
* @return array<float>
*/
private function resolutionFromJfifHeader($handle): array
{
// read first 20 bytes
rewind($handle);
$header = fread($handle, 20);
// find the JFIF segment
$offset = strpos($header, 'JFIF');
if ($offset === false) {
throw new AnalyzerException('Unable to read JFIF header');
}
// read bytes at known offsets relative to JFIF
$units = ord($header[$offset + 7]);
$x = unpack('n', substr($header, $offset + 8, 2))[1];
$y = unpack('n', substr($header, $offset + 10, 2))[1];
if ($units === 2) { // unit is dots per cm → convert to DPI
return [round($x * 2.54), round($y * 2.54)];
}
return [$x, $y]; // unit is DPI or no unit
}
/**
* @param resource $handle
* @throws MissingDependencyException
* @throws AnalyzerExceptionView on GitHub (pinned to 5598b9e397)
Solutions
- Nothing to fix from user land; EXIF and pHYs parsers run next automatically
- If you need JFIF density honored, re-encode with a JFIF header (imagemagick 'convert -density 96')
- For debugging, inspect the first bytes yourself: bin2hex(substr(file_get_contents($path), 0, 20))
Defensive patterns
Strategy: fallback
Prevention
- Internal step only; EXIF and pHYs parsers follow automatically
- Re-encode JPEGs with a JFIF header when JFIF density is required
- Do not build logic that depends on which internal recovery branch failed
When it happens
Trigger: JPEG files whose first segment is APP1/EXIF (camera files) or APP14/Adobe instead of APP0/JFIF; files that are not JPEG at all; truncated headers shorter than the JFIF offset.
Common situations: Camera-origin JPEGs (EXIF first), Photoshop-exported Adobe JPEGs, or renamed non-JPEG files being inspected for resolution.
Related errors
- Input must be PNG format
- Failed to read image resolution
- Unable to read resolution from path
- Unable to read exif data
- Unable to read exif data, division by zero
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/9d4a23a0c9d356f5.
Report an issue: GitHub.