-
Notifications
You must be signed in to change notification settings - Fork 229
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
Support for reading and writing PNG metadata #165
Conversation
}; | ||
|
||
Image.prototype.setMetadata = function(data) { | ||
this.__metadata = data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are different types of 'data' handled?
Eventually this value will go all the way to here, at which time it will be casted to a string.
If users pass here an object, for example, do they expect us to serialize it for them? What if they pass in a function?
In the docs we say that 'data' should be a string. So we should probably enforce it here by doing type checks and throwing an exception if needed, as done in other methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I think it would make sense to only allow metadata to be set to a string, so I added that check.
I've also added the option to pass in null
to setMetadata, which will cause the image to be saved without any tEXt chunks when writeFile
is called.
@joannajw It looks great. Please see the comments I've added. Thanks! P.S. please add the |
Thanks for the comments! I've made the changes you mentioned and removed unnecessary comments. Let me know what you think. |
Support for reading and writing PNG metadata
@joannajw I'll release a new version of lwip with your changes shortly. |
Thanks so much for the merge! I was wondering if you have an idea of when a new release will be made, so we can update our project to incorporate the new feature as well? |
@joannajw I'll try to push it this weekend. |
Awesome, thanks! |
@@ -53,5 +53,9 @@ string decode_jpeg_buffer(char * buffer, size_t size, CImg<unsigned char> ** cim | |||
jpeg_finish_decompress(&cinfo); | |||
jpeg_destroy_decompress(&cinfo); | |||
|
|||
// TODO: implement getting metadata from GIFs; this is a placeholder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comment should this:
// TODO: implement getting metadata from JPEGs; this is a placeholder
This pull request adds the feature requested in issue #164. It adds support for writing and reading metadata in PNG files.
setMetadata()
sets a PNG tEXt chunk with the keylwip_data
and comment as the input string.getMetadata()
returns the contents of the first tEXt chunk found with the keylwip_data
, or null if none exists.Setting metadata:
Getting metadata: