Skip to content

[6.x] Read only the header to get image dimensions on remote disks - #15979

Open
edalzell wants to merge 13 commits into
statamic:6.xfrom
edalzell:image-header-attributes
Open

edalzell wants to merge 13 commits into
statamic:6.xfrom
edalzell:image-header-attributes

Conversation

@edalzell

@edalzell edalzell commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Part of #15970 (Group B).

Imaging\Attributes::from() copied the whole image off a remote disk to read its dimensions. Now it reads the first 64 KB, doubling up to 2 MB until the dimensions and EXIF orientation are readable, and falls back to the full copy if that isn't enough. S3 uses ranged requests via S3MetadataStream (256 KB chunks), since Laravel's S3 readStream() downloads the whole object by default. Local disks and SVGs are unchanged.

Depends on #15934 for S3MetadataStream, so its commits show in the diff until it lands. Only src/Imaging/Attributes.php, the $chunkSize argument on S3MetadataStream, tests/Fakes, tests/Imaging/RemoteAttributesTest.php and tests/Search/InsertMultipleJobAssetsTest.php belong to this PR.

For #14061, InsertMultipleJobAssetsTest asserts that InsertMultipleJob on a remote disk reads image headers rather than whole files, reads nothing when sidecars exist, resumes where it left off when retried, reads nothing when run again, and still only reads headers when saving an asset rebuilds a missing index.

Not tested against a real S3 bucket.

Benchmark

20 images of 2 MB each plus a PDF, on a counting fake remote disk. The fake exercises the generic stream path, not the S3 ranged path.

Bytes read from the disk:

Scenario Before This PR
generateMeta, 20 images 40.00 MB 1.69 MB
InsertMultipleJob, cold cache, no sidecars 40.00 MB 1.69 MB
InsertMultipleJob retried after dying halfway 20.00 MB 1.06 MB

All disk operations with this PR:

Scenario object_reads object_bytes meta_reads lists heads writes
generateMeta, 20 images 20 1.69 MB 0 1 60 0
InsertMultipleJob, cold cache, no sidecars 20 1.69 MB 21 1 63 21
InsertMultipleJob again, warm cache 0 0.00 MB 0 0 0 0
InsertMultipleJob, cold cache, sidecars present 0 0.00 MB 21 1 0 0
InsertMultipleJob retried after dying halfway 10 1.06 MB 10 0 30 10

@edalzell
edalzell marked this pull request as ready for review November 20, 2026 00:14

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants