Skip to content

Add ImageMetadataBuffer helper for partial‐file XMP buffering #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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
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.

1 participant