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 AnalyzerException

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Nothing to fix from user land; EXIF and pHYs parsers run next automatically
  2. If you need JFIF density honored, re-encode with a JFIF header (imagemagick 'convert -density 96')
  3. For debugging, inspect the first bytes yourself: bin2hex(substr(file_get_contents($path), 0, 20))
Defensive patterns

Strategy: fallback

Prevention

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


AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23). Data as JSON: /api/errors/9d4a23a0c9d356f5. Report an issue: GitHub.