Load the photo, call StripMetadata(), and save. The new file has no EXIF, XMP or IPTC block, so no GPS position, camera serial or capture time. Load has already turned the photo upright, so removing the orientation tag doesn’t turn it sideways. The program below cleans a Nikon photo with GPS from the public exif-samples collection.
dotnet new console -o StripExif && cd StripExif dotnet add package RecursiveAI.OneImage --version 1.10.4 repo=https://raw.githubusercontent.com/ianare/exif-samples/master curl -L -o gps.jpg $repo/jpg/gps/DSCN0010.jpg
OneImage needs the .NET 10 SDK. Put this in Program.cs and run dotnet run:
using OneImage; static void Show(string file) { ExifData? exif = Image.Identify(file).Metadata.ReadExif(); string gps = exif?.Gps is GpsPosition p ? $"{p.Latitude:F4}, {p.Longitude:F4}" : "none"; string block = exif is null ? "none" : "present"; Console.WriteLine($"{file}: EXIF {block}, GPS {gps}"); } Show("gps.jpg"); // Everything but the pixels goes; keepIcc: true keeps the color profile. Image.Load("gps.jpg").StripMetadata(keepIcc: true).Save("public.jpg"); Show("public.jpg");
gps.jpg: EXIF present, GPS 43.4674, 11.8851 public.jpg: EXIF none, GPS none
StripMetadata() without arguments also drops the ICC color profile, which can shift the colors of photos in wide-gamut spaces such as Adobe RGB; keepIcc: true keeps it.
Strip and resize in one call
For web copies, Image.Thumbnail resizes, turns the photo upright, converts it to sRGB (so the colors stay right without the original profile) and removes EXIF, XMP and IPTC:
using OneImage; Image.Thumbnail("gps.jpg", 400).Save("thumb.jpg"); bool hasExif = Image.Identify("thumb.jpg").Metadata.ReadExif() is not null; Console.WriteLine($"thumb.jpg: {(hasExif ? "EXIF present" : "no EXIF")}");
thumb.jpg: no EXIFLimits
- The file is re-encoded. Removing metadata this way decodes and encodes the JPEG again, at quality 75 unless you set
JpegEncoderOptions.Quality. OneImage doesn’t rewrite a JPEG’s metadata in place. - It’s all or nothing. You can keep the ICC profile, but not, say, the copyright field alone. To keep everything except a few tags, use a dedicated EXIF editor.
- Plain
LoadandSavekeep metadata, GPS included, so stripping has to be explicit, unless you useThumbnail.
To read the fields before removing them, see Read EXIF data. Metadata handling is in the guide.