Skip to content
Snippets Groups Projects

Draft: Add ID to metadata of the png file

Closed Mayr, Hannes requested to merge 81-add-id-to-figure-file-metadata into dev
2 unresolved threads
+ 11
2
@@ -55,15 +55,24 @@ def save_plot(figures, plot_names, extension="png"):
raise IndexError("There are more plot names than figures.")
plot_path = []
exif_data_mpl = {
"Title": "Heyho",
"Author": "blub",
"Description": "Identiplier",
"Copyright": "R",
"Comment": "Test",
}
for i, fig in enumerate(figures):
if isinstance(fig, matplotlib.figure.Figure):
plt.figure(fig)
plot_path.append(plot_names[i] + ".tmp." + extension)
plt.savefig(plot_path[i])
plt.savefig(plot_path[i], metadata=exif_data_mpl)
elif all(x in str(type(fig)) for x in ["PIL", "ImageFile"]):
plot_path.append(plot_names[i] + ".tmp." + extension)
fig.save(plot_path[i])
img_exif = fig.getexif()
img_exif[270] = "Identiplier2"
fig.save(plot_path[i], exif=img_exif)
else:
raise TypeError(f"Figure number {i} is not a valid figure object.")
Loading