Draft: Add ID to metadata of the png file
I was able to add something to the metadata of the png file in the case of the Image engine. We have to choose which exif tag the ID should be written to since they are predefined and standarized. I suggest "Description" or "Comment".
For matplotlib I was also able to write something to the exif fields "Title" and "Author". Unfortunately, both "Description" and "Comment" do not work. Although according to their documentation they should: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html
When I say it does not work, I mean that my file browser does not show these two fields but the other ones.
If we don't get it to work via mpl, we still can do it the same way as for the image engine by opening the image with PIL after the export via mpl. But I like it more if the metadata is set directly with the original export.
Closes #81
Merge request reports
Activity
changed milestone to %Version 0.3.0
added improvement priorityhigh python statusto do labels
assigned to @hannes.mayr
added 1 commit
- 798c0f50 - Add unittests for writing IDs to metadata. The test for mpl still fails as...
I believe this is a problem in the png specification, which originally doesn't support exif. https://stackoverflow.com/questions/9542359/does-png-contain-exif-data-like-jpg
It was added in some extension, but I could not find a picture viewer that would recognize these EXIF metadata.
This is another variant, but it won't be recognized by picture viewers either. https://stackoverflow.com/questions/58399070/how-do-i-save-custom-information-to-a-png-image-file-in-python
mentioned in issue #102 (closed)
Neither the exif via mpl or pillow directly is displayed for me (tested with xnview / Irfanview / windows explorer)
Gimp did show the comment, but none of the other entries.With this website I could confirm the pillow version is working (https://www.metadata2go.com/)
And it also shows all entries for the matplotlib version.But we can see, that generally support for metadata in .png is not good - so for .png we should look for an alternative.
Which means we'd have to filter out png as file format.Edited by Hock, MartinSo this means it works generally, but the viewers do not display it correctly, right?
If that is the case, we could just finish this part of the code and leave it working. Some of the viewers will display it, others not. But we don't rely on it and also put the metadata in a text file as originally intended. What do you think?I'm still not sure, whether we're using an extension to a standard that just hasn't been adopted, or whether we're using something rather proprietary.
But yes - as long as it does not produce problems we could leave the code. It doesn't feel like proper practice though.As for a txt - the folder is named with the ID, so for ease of use, that should be enough. If we gather more metadata to add there, we can create an additional .txt.
I believe we can add this merge request, but leave the issue about metadata on file open.
- Resolved by Mayr, Hannes
@m.hock Did you have a look at the CITATION.cff? Are the contents okay for now?
As summary, we have several options how to proceed with the metadata for the plots/pictures:
- Leave this MR open (low effort, no picture metadata)
- Merge the MR and set metadata in the mpl and the image engine. (low effort, but can raise problems in future releases)
- Merge the MR and change the code so that metadata is set after export, so it works for every (future) engine. (higher effort, can raise problems in future releases)
mentioned in merge request !58 (merged)
removed priorityhigh label
added prioritymedium label
This merge request is about PNG files only but, in the bigger picture, we don't want to limit ourselves to a single file system.
EXIF is officially supported for most JPEG and TIFF. Others have new specs which are not widely supported. And then there is the possibility of adding .exif files.
There are also other metadata standards, which might support the same and other files.We will hault this and continue with the metadata during execution (container object, outputs), file and folder names for now.
Decided to close the MR, the options are not satisfactory. We'd rather look to adding more universal metadata via a file or inside an RO-Crate &10