Skip to content

feat: Add withXmp() method for XMP metadata injection #4416

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

Closed
wants to merge 2 commits into from

Conversation

tpatel
Copy link
Contributor

@tpatel tpatel commented Jun 16, 2025

partially resolves #4143

  • Add withXmp(xmpBuffer) method to embed custom XMP metadata in output images
  • Include parameter validation for non-Buffer inputs
  • Add tests
  • Update API documentation


- <code>Error</code> Invalid parameters

**Since**: 0.33.0
Copy link
Contributor Author

@tpatel tpatel Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the version will need to be updated depending on when this is merged

/**
* Set XMP metadata in the output image.
*
* @since 0.33.0
Copy link
Contributor Author

@tpatel tpatel Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this version string will need an update too

@lovell
Copy link
Owner

lovell commented Jun 18, 2025

Bonjour, thank you very much for the PR Thibaut, its always a pleasure to see tests.

I think it might be easier both for external API usage as well as internal implementation, if this new method accepts a string rather than a Buffer.

withXmp(xmp: string)

I realise this would differ from the existing metadata() call that always returns the raw XMP as a Buffer, but this is primarily due to the chance of there being a UTF-16 byte-order mark at the start.

If we can, given we're in control of the input, let's enforce a standard JavaScript string (UTF-16 sous le capot), which the C++ internals can then access as a UTF-8 std::string via Node API / V8 to pass to libvips.

(As a separate discussion, it might be worth exposing the XMP metadata as a standardised JavaScript string instead of, or as well as, a Buffer.)

@lovell
Copy link
Owner

lovell commented Jun 21, 2025

I took a quick look at exposing XMP metadata as a string. Commit 6f4ce5b out on the xmp-as-string WIP branch seems to work for the most common case where the metadata is already valid UTF-8. I need to find some more examples to test and possibly further improve this e.g. big and little endian UTF-16.

@tpatel
Copy link
Contributor Author

tpatel commented Jul 3, 2025

@lovell thanks for the feedback, it does make it easier to provide a string. I've edited my code, doing the string to Buffer conversion on the JavaScript side. Let me know if this is what you had in mind.

I've chosen not to venture on adding XMP metadata parsing as string for now, as it could be a good thing to do in a separate PR.

Let me know what you think!

tpatel added 2 commits July 3, 2025 09:45
partially resolves lovell#4143

- Add withXmp(xmpBuffer) method to embed custom XMP metadata in output images
- Include parameter validation for non-Buffer inputs
- Add tests
- Update API documentation
- this will be more user-friendly for folks who want to edit the XMP metadata
@tpatel tpatel force-pushed the thibaut/add-xmp-metadata-override branch from 19c0cae to 1d93e2e Compare July 3, 2025 07:45
@tpatel
Copy link
Contributor Author

tpatel commented Jul 3, 2025

note: I've just force pushed to rebase on top of main

@lovell lovell added this to the 0.34.3 milestone Jul 4, 2025
@lovell
Copy link
Owner

lovell commented Jul 4, 2025

Landed via commit 4e3f379

I removed the manual memory copying as the use of a string means we can pass it all the way through from JS to libvips, plus added a partnering keepXmp function for consistency with keepExif.

(I also added the XMP-as-a-string feature via commit 8ee8d27)

Thank you very much Thibaut for your work on this, it will be part of the forthcoming 0.34.3 release.

@lovell lovell closed this Jul 4, 2025
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.

Enhancement: add/update XMP and IPTC metadata
2 participants