Easier way to remove metadata from processed images #226
-
I've noticed that by default all metadata is retained in the processed image (which seems like a very reasonable default). This can be catastrophic for the files size though, especially if you're creating thumbnail sized images, but the metadata still includes an EXIF thumbnail and/or metadata that's bigger then the actual image data. It's easy to nuke all metadata using the following configuration: options.OnBeforeSaveAsync = formattedImage =>
{
formattedImage.Image.Metadata.ExifProfile = null;
return Task.CompletedTask;
}; But that would also remove any EXIF orientation, etc. from the image. Does ImageSharp support metadata categories (if not, would it make sense to add them?) and/or would you be open to have this easily configured by specifying an enum of categories to keep/remove? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There's some very loose (lots of "other") categorization in the EXIF specification but that's informative and not part of any stored data. I don't think we'd ever try to add explicit categorization to our API. It's a lot of work to maintain with very little benefit. If individuals want to preserve only a subset of the data they would be better off iterating an enumerated collection of tags from // Stored as a static collection somewhere.
ExifTag[] requiredTags = { ExifTag.Orientation };
if (formattedImage.Image.Metadata.ExifProfile != null)
{
ExifTag[] tags = formattedImage.Image.Metadata.ExifProfile.Values.Select(x => x.Tag).ToArray();
for (int i = 0; i < tags.Length; i++)
{
if (Array.IndexOf(requiredTags, tags[i]) == -1)
{
formattedImage.Image.Metadata.ExifProfile.RemoveValue(tags[i]);
}
}
} |
Beta Was this translation helpful? Give feedback.
There's some very loose (lots of "other") categorization in the EXIF specification but that's informative and not part of any stored data.
I don't think we'd ever try to add explicit categorization to our API. It's a lot of work to maintain with very little benefit.
If individuals want to preserve only a subset of the data they would be better off iterating an enumerated collection of tags from
ExifProfile.Values
and removing each one