How to Strip Location and Serial Numbers From Photos Before Sharing
Making a photo smaller does not necessarily make it anonymous. I resized a test JPEG with ImageMagick's -resize 50%, and the copy still had its GPS position, camera body serial, lens serial, owner name and an embedded thumbnail.
The goal here is a separate, scrubbed copy that you have actually checked, with the original left alone. The commands were tried with ExifTool 13.50 on generated test files with metadata planted in them.
Look at what the file is carrying
Install ExifTool (the package is libimage-exiftool-perl on Debian and Ubuntu), then ask it for everything:
exiftool -a -G1 -s -ee photo.jpg
The flags matter because the same fact can be stored in several places:
-ashows duplicate tags instead of picking one.-G1shows which block each tag lives in.-sprints real tag names, which you can reuse in commands.-eealso digs into embedded data.
Look for GPS, anything containing Serial, OwnerName, creator or by-line fields, place names such as City, capture times and ThumbnailImage. A serial in the EXIF block may have a twin in XMP, so deleting one named tag is a poor strategy.
Quick detour: that thumbnail is a second, tiny picture stored inside the first. If an editor crops the main image but fails to regenerate the thumbnail, the thing you cropped out is still there. It is a wonderfully daft failure.
Delete everything, then copy back the little you need
It is safer to remove the lot and restore a short allowlist than to hunt for bad tags one at a time.
mkdir clean
exiftool -all= -tagsfromfile @ -Orientation -ColorSpaceTags \
-o clean/photo.jpg photo.jpg
Here is what each part does:
-all=deletes the metadata ExifTool is able to remove.-tagsfromfile @copies selected tags back from the source file.-Orientationkeeps the instruction that says which way up to display it.-ColorSpaceTagskeeps colour information, including any ICC profile.-owrites a new file, so the original is untouched.
Do not drop the orientation tag by accident. Many cameras store the pixels one way and rely on that tag to rotate them. Plain -all= removes it, so a portrait shot can arrive sideways. Colours can also shift if you discard the ICC profile.
In my test the GPS tags, EXIF and XMP serials, owner name, IPTC by-line, comment and thumbnail all went. So did some junk I had appended after the end of the JPEG.
Removing appended data has a cost: extras tacked onto a photo, such as the video half of a motion photo, or data behind depth and HDR effects, may be lost. For a shared copy I think that is usually the right trade.
Script it so a failed scrub is loud
This version handles several files, gives them dull new names and checks each output. Save it as scrub.sh:
#!/bin/sh
# usage: sh scrub.sh OUTDIR PHOTO...
set -eu
out=$1
shift
mkdir "$out" # fails if it exists, so old files cannot sneak in
exiftool -all= -tagsfromfile @ -Orientation -ColorSpaceTags \
-o "$out/photo-%.4C.%le" "$@"
for f in "$out"/*; do
left=$(exiftool -q -a -ee -G1 -s '-*GPS*' '-*Serial*' '-*Owner*' "$f")
if [ -n "$left" ]; then
printf '%s still has:\n%s\n' "$f" "$left" >&2
exit 1
fi
done
echo "clean copies are in $out"
sh scrub.sh to-share IMG_1234.jpg IMG_1235.jpg
The output names are photo-0000.jpg, photo-0001.jpg and so on. Filenames are metadata too: names from cameras and phones often include a date, and your own might include a street or a person.
A checker you have only ever seen pass has not told you much, so I tested this one by swapping the stripping options for a harmless edit and running it on a dirty file. It listed the GPS, serial and owner tags and exited with status 1.
It is still a narrow check, aimed at three families of tag names. Run the full listing from the first section on a sample output and read it, especially for a camera or app you have not handled before.
Watch the formats that behave differently
JPEG is the easy case. Be more careful with these:
- RAW files: do not run
-all=on them. ExifTool's author warns that some of their metadata is needed to render the image. Export a JPEG and scrub that. - HEIC: I did not test it. Inspect the output and open it to check rotation and colour, or export to JPEG first.
- PNG: a test file with an XMP latitude and a text comment came out without them, but inspect your own.
- Video: treat it as a separate job. This script has not been tested on it.
If you use ImageMagick, say strip
If you are re-encoding anyway, you can use this command, which removed the planted GPS and serial tags in my test:
magick photo.jpg -auto-orient -strip smaller.jpg
The order matters because -auto-orient rotates the actual pixels while the orientation tag still exists, then -strip throws the metadata away. It also removes the colour profile, and saving a JPEG again is lossy, so ExifTool is my default when the picture itself need not change.
On a phone, check what the switch covers
On an iPhone, Apple's instructions are to select the photos, tap Share, then Options, turn off Location and tap Done before choosing where to send them.
Google Photos has its own location controls, but its help page distinguishes between locations added by the camera and those estimated or added by hand. They cannot all be edited the same way.
Treat a location switch as covering location only. If the other fields, such as serial numbers, matter, send yourself the exact file the share process produces and inspect it with ExifTool. Do not assume a messaging app or website will clean it for you, and remember that the service receiving an upload may see the file before it strips anything.
The pixels can still give you away
Metadata removal does nothing about what is visible. Before sending, zoom in and look for:
- street signs, house numbers and distinctive views
- number plates, parcel labels, badges and screens
- serial stickers on the equipment you photographed
- reflections in windows, glasses and shiny appliances
Crop or paint over these with a solid block, export a flattened image, and then scrub that export, because editors can add metadata of their own.
Hang on, can a camera be identified with no serial at all? Potentially, yes. Tiny manufacturing differences between sensor pixels leave a noise pattern, which forensic researchers can compare across images. ExifTool does not touch it, so a clean tag listing is no promise that two photos cannot be linked.
For an ordinary sale listing or forum post, removing metadata and checking the frame deals with the obvious leaks. If being linked to the camera would put someone in danger, think hard about whether to publish the photo at all.