Skip to content

Conversation

klaari
Copy link
Contributor

@klaari klaari commented Jun 5, 2025

This PR introduces a new ImageMetadataBuffer helper that reads only the minimal bytes
required from a PNG/JPEG/WebP to locate XMP metadata, rather than downloading the entire file.
That reduces memory usage and bandwidth when extracting XMP from large images.

Usage example:

use CSD\Image\Buffer\ImageMetadataBuffer;
use CSD\Image\Image;

$url = 'https://example.com/photo.png';
$string = ImageMetadataBuffer::bufferUpThroughXmp($url);
$image  = Image::fromString($string);
$xmp    = $image->getXmp();

- Introduce CSD\Image\Buffer\ImageMetadataBuffer to read just enough of PNG/JPEG/WebP files (from URLs or local paths) to capture embedded XMP metadata
- PNG: buffer chunk-by-chunk until an iTXt chunk starting with “XML:com.adobe.xmp\x00” or IEND
- JPEG: buffer segment-by-segment until APP1-XMP and first SOF, then append EOI
- WebP: buffer RIFF sub-chunks until “XMP ” or “EXIF” chunk is found
- Falls back to full file read only if fopen() fails or format is unrecognized
@lourot
Copy link
Member

lourot commented Jun 9, 2025

Hi @klaari sorry for the slow reaction and thanks for the PR! I should be able to find some time in the upcoming days

@lourot lourot merged commit 0bdfe9f into Frameright:master Jun 15, 2025
5 checks passed
@lourot
Copy link
Member

lourot commented Jun 15, 2025

Looks great, thanks @klaari! Released as v1.2.0

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