I have some JPEG files uploaded by users. I need to be sure they are "clean". Sure, I can just recompress them to JPEG again and I will get "clean" files but either I will loose quality or files will be bigger.

So how can I repack JPEG files? I mean how can I loslessy copy "body" of the compressed JPEG but strip anything else (all comments, EXIF, zero bytes appended to files etc.)? I have seen some JPEG files with ZIP files appended to them. People use them to post as a JPEG but then they download, unpack the ZIP and have some special content hidden from site moderators. I want to avoid that too.


You can use jpegtran -copy none -optimize for that.

  • 1
    You beat me to it! But yes, jpegtran is a life-saver. – Wyatt8740 Apr 17 '17 at 23:38
  • 1
    @Tom Sometimes, -progessive result in smaller files than -optimize. – user2233709 Apr 21 '17 at 14:34
  • 1
    @user2233709 progressive JPEGs however don't work well with lepton and guetzli, which may not appear like a problem but the developers of those projects also brought up that progressive doesn't work well on mobile devices. Just a heads up. – LiveWireBT Apr 21 '17 at 23:42
  • 1
    @user2233709 github.com/dropbox/lepton a tool dropbox developed to store JPEGs more efficiently in their data centers, quite useful if you want to backup a large amount of JPEGs and want to reduce the file size of the backup by ~10-20%, back and forth conversion also helps identifying broken files (you won't be able to convert them, but you know which one are broken then) github.com/google/guetzli the latest released research project from Google in the line of zopfli and brotli trying to improve a particular compression technology (or inventing a new one) – LiveWireBT Apr 22 '17 at 13:43
  • 1
    @LiveWireBT Thanks for pointing these. Aren’t they better options than my suggested jpegtran? Should’t you propose them in a answer? – user2233709 Apr 22 '17 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.