Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I clear an Image's EXIF data with ImageSharp?

I found a GitHub issue showing how to remove an Image's exif data by setting its ExifProfile to null:

 SixLabors.ImageSharp.Image image = Image.Load(imagePath);

 //remove exif
 image.Metadata.ExifProfile = null;
    
 //resize
 image.Mutate(x => x.Resize(width, height));
    
 //save
 SixLabors.ImageSharp.Formats.Jpeg.JpegEncoder encoder = new SixLabors.ImageSharp.Formats.Jpeg.JpegEncoder();
    
 encoder.Quality = 30; 
                        
 image.Save(thumbnailPath, encoder);

...but it doesn't seem to work for me -- the saved jpeg's are the same size, and my when inspected by my OS they show me all the camera's EXIF settings. When I do this same inspection on images created from another utility the OS does not show me all the EXIF settings...so I'm inclined to say this ImageSharp technique is not scrubbing them correctly.

Any idea?

https://github.com/SixLabors/ImageSharp/issues/400

like image 451
mdelvecchio Avatar asked Oct 15 '25 03:10

mdelvecchio


1 Answers

Turns out there are two different types of metadata - EXIF and XMP. It is necessary to set both objects to null to remove them all:

image.Metadata.ExifProfile = null;
image.Metadata.XmpProfile = null;
like image 148
mdelvecchio Avatar answered Oct 17 '25 19:10

mdelvecchio