Skip to content
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

Add the possibility to create PNG with meta information #26

Closed
lpatiny opened this issue Jul 14, 2022 · 6 comments
Closed

Add the possibility to create PNG with meta information #26

lpatiny opened this issue Jul 14, 2022 · 6 comments

Comments

@lpatiny
Copy link
Member

lpatiny commented Jul 14, 2022

When encoding an image we would need to be able to add textual information following the specifications:

https://www.w3.org/TR/PNG/#11textinfo

We should also ensure that decoding can read those information.

@targos
Copy link
Member

targos commented Feb 11, 2024

Do you have an example of file with such textual information so we can understand:

  • Which chunk is most appropriate for it
  • How the API should look like to pass it to the encoder

@lpatiny
Copy link
Member Author

lpatiny commented Feb 12, 2024

I guess one idea is that when you copy a molecule as PNG we can insert the smiles or molfile in it so that if we somehow copy it back from another software we cane extract the chemical structure.

Using imagemagick we can add a new keyword in a PNG using:

convert butane.png -set 'Smiles' 'CCCC' butane_meta.png

We can check if the keyword has been added using identify --verbose butane_meta.png

You will find here both images before and after adding the Smiles

Archive.zip

There are 3 possible chunks:

  • tEXt for ASCII < 128
  • iTXt for UTF-8
  • zTXt for zlib compressed data

@stropitek
Copy link

FWIW excalidraw exports a png with a json in the metadata so that it can be re-edited:

CleanShot 2024-02-13 at 10 24 31

This is the png with the embedded data:
excalidraw_export_embed

@targos
Copy link
Member

targos commented Feb 13, 2024

Both your examples use the tEXt chunk, so we only need to implement the encoder part of it.

BTW, thanks @stropitek for your example, it made me realize that the decoding was wrong. Fixed in #39

@targos
Copy link
Member

targos commented Feb 13, 2024

@lpatiny is latin1 enough for your use case?

targos added a commit that referenced this issue Feb 13, 2024
@lpatiny
Copy link
Member Author

lpatiny commented Feb 13, 2024

Yes latin1 is enough for SMILES and molfile.

targos added a commit that referenced this issue Feb 13, 2024
targos added a commit that referenced this issue Feb 13, 2024
@targos targos closed this as completed in ff545ce Feb 13, 2024
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

No branches or pull requests

3 participants