A metadata-removal script should produce a photograph that is still useful. For a phone image, that means more than clearing the camera model or location. You also need to decide what happens to orientation, colour, transparency and JPEG compression.

Python's Pillow library is a practical starting point for building image exports. The example below deliberately creates a new JPEG from rendered pixels. It removes the source metadata by not carrying the source image's information dictionary into the new image. It is not a lossless file-container editor.

WHY PHOTOS SOMETIMES TURN SIDEWAYS

EXIF Orientation tells an image viewer how to rotate or mirror the stored pixels. Removing this field alone does not rotate those pixels. Pillow's ImageOps.exif_transpose applies the orientation transformation and removes the now-unnecessary orientation instruction from the transformed result.

Apply this step while the source information is still available. Then construct the clean image and save it with explicit output options. Do not copy the original EXIF block back into the export after doing the transformation.

A CONTROLLED PILLOW EXAMPLE

Install Pillow in your own Python environment:

python -m pip install Pillow

Then use this function for an RGB JPEG export:

from pathlib import Path
from PIL import Image, ImageOps

def clean_photo(source, destination):
source = Path(source)
destination = Path(destination)
if source.resolve() == destination.resolve():
raise ValueError("Use a separate destination file.")
with Image.open(source) as original:
if getattr(original, "n_frames", 1) != 1:
raise ValueError("Animated files need a separate workflow.")
if original.mode not in ("RGB", "RGBA", "L", "LA", "P"):
raise ValueError("Convert this colour mode explicitly first.")
oriented = ImageOps.exif_transpose(original)
rgba = oriented.convert("RGBA")
rgb = Image.new("RGB", rgba.size, "white")
rgb.paste(rgba, mask=rgba.getchannel("A"))
rgb.info.clear()
rgb.save(destination, format="JPEG", quality=92, exif=b"")

clean_photo("original.jpg", "original-clean.jpg")

The destination is always a JPEG in this example. Transparency is composited onto white, and multi-frame input is rejected instead of silently losing animation. The function intentionally rejects specialised colour modes so a generic conversion is not mistaken for a managed print workflow.

DECIDE WHAT TO DO WITH COLOUR PROFILES

An ICC profile is not the same thing as a GPS coordinate, but it is still embedded data. This example does not preserve it. For a colour-managed workflow, convert to an appropriate output space or deliberately attach a reviewed profile. Simply discarding a profile can change how wide-gamut photographs appear in other applications.

Likewise, quality=92 is an output preference. It does not mean the picture has a measurable 92% of its original visual quality. Repeated JPEG exports can introduce additional loss. If your task requires unchanged encoded image data, use a tool designed to edit the supported file containers rather than decode and recompress them.

CHECK THE OUTPUT, NOT JUST THE FUNCTION CALL

Reopen a cleaned image and inspect getexif(), dimensions and visual orientation. Also inspect it with a separate metadata reader: an empty EXIF result is not a comprehensive audit of XMP, comments or every possible container. Test the exact input types used by your application.

Preserve Pillow's protections against decompression bombs and treat untrusted images as potentially resource-intensive. For a production uploader, limit file size, pixel count and execution time, and process files in an appropriately restricted environment.

Python is useful when you need repeatable local scripts or a batch pipeline. If you only need to clean a few pictures, visit https://stripaitags.com/ and review the browser tool's report. This tutorial is a developer option; it does not mean StripAITags requires Python on its website server.

Further reading
Pillow orientation operations: https://pillow.readthedocs.io/en/stable/reference/ImageOps.html
Pillow file format options: https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html
Pillow security guidance: https://pillow.readthedocs.io/en/stable/handbook/security.html