How to remove EXIF data without recompressing the JPEG?

I want to remove the EXIF information (including thumbnail, metadata, camera info... everything!) from JPEG files, but I don't want to recompress it, as recompressing the JPEG will degrade the quality, as well as usually increasing the file size.

I'm looking for a Unix/Linux solution, even better if using the command-line. If possible, using ImageMagick (convert tool). If that's not possible, a small Python, Perl, PHP (or other common language on Linux) script would be ok.

There is a similar question, but related to .NET.


exiftool does the job for me, it's written in perl so should work for you on any o/s

https://exiftool.org/

usage :

exiftool -all= image.jpg

UPDATED - as PeterCo explains below this will remove ALL of the tags. if you just want to remove the EXIF tags then you should use

exiftool -EXIF= image.jpg

With imagemagick:

convert <input file> -strip <output file>

ImageMagick has the -strip parameter, but it recompresses the image before saving. Thus, this parameter is useless for my need.

This topic from ImageMagick forum explains that there is no support for JPEG lossless operations in ImageMagick (whenever this changes, please post a comment with a link!), and suggests using jpegtran (from libjpeg):

jpegtran -copy none -progressive image.jpg > newimage.jpg
jpegtran -copy none -progressive -outfile newimage.jpg image.jpg

(If you are unsure about me answering my own question, read this and this and this)


You might also want to look into Exiv2 -- it's really fast (C++ and no recompression), it's command line, and it also provides a library for EXIF manipulation you can link against. I don't know how many Linux distros make it available, but in CentOS it's currently available in the base repo.

Usage:

exiv2 rm image.jpg

I'd propose jhead:

man jhead
jhead -purejpg image.jpg

Only 123Kb on debian/ubuntu, it's fast, and it only touches EXIF keeping the image itself intact. Note that you need to create a copy if you want to preserve the original file with EXIF in it.