How can I preserve image quality while stripping EXIF GPS data from user uploads on a Linux web server?

I run a small web app where users upload photos, and I need to strip EXIF metadata (especially GPS coordinates and camera serial numbers) before the images are served back to visitors.

Current setup: Ubuntu 22.04, Nginx, PHP 8.2 with Imagick available. Right now I call $image->stripImage() in Imagick right after upload, which removes metadata but also seems to drop the ICC colour profile, so some photos look slightly washed out compared to the originals.

What I have tried:

  • exiftool -all= image.jpg via shell: removes everything, including colour profiles.
  • Imagick stripImage() followed by profileImage() to re-add an sRGB profile from a local ICC file. This works, but I am not sure it is the right approach for images that already carry a calibrated AdobeRGB profile.
  • Checking available tooling lists such as https://aicrazy.org/ to see whether any dedicated image-cleanup utility would avoid re-encoding entirely, but most of what I find there is web-based and would mean uploading user photos to a third party, which is not acceptable for this app.

Questions:

  1. Is there a way to remove only the EXIF/GPS tags while keeping the existing ICC profile intact, without a full re-encode?
  2. If re-encoding is unavoidable, what is the recommended quality setting with Imagick/lossless JPEG transforms to avoid generational loss?

Any pointers toward a lossless or profile-preserving workflow would be appreciated.