How to strip JPEG metadata in Ubuntu

If you want to post some JPEG pictures but you’re worried that they might have metadata like location embedded in them, here’s how to strip that data out.

First, install exiftool using this command:

sudo apt-get install libimage-exiftool-perl

Then, go into the directory with the JPEG files. If you want to remove metadata from every file in the directory, use

exiftool -all= *.jpg

The exiftool will make copies, so if you had a file called image.jpg, when you’re done you’ll have image.jpg with all the metadata stripped plus a file called image.jpg_original which will still have the metadata.

31 Responses to How to strip JPEG metadata in Ubuntu (Leave a comment)

  1. Nice. I am not expert, but a while back made some study and wrote a little tutorial. Maybe useful to other newbies. 〈How to View Comments in JPEG, PNG, MP3 files? (ExifTool Tutorial)〉 http://xahlee.org/img/metadata_in_image_files.html

  2. Also you can use jpegtran, which is part of libjpeg and should be in every desktop distro out there:

    jpegtran -copy none -outfile dst.jpg src.jpg

    All transformations are lossless.

  3. Does this just remove EXIF metadata or all metadata (IPTC, etc) from the image? I think that needs to be made clear in the post. Users might think EXIF is the only kind of metadata that is in an image.

  4. Alex

    To strip all metadata except for location one:
    exiftool -all= -tagsfromfile @ -gps:all *.jpg

  5. Does Ubuntu have jpegoptim tool in repo’s ? Debian has it, so Ubuntu must have as well,
    there is a better idea:

    ~$ jpegoptim –strip-all *.jpg

    ( or can use –strip-com or –strip-exif )
    As a nice “side effect” the picture is optimized, and can become even smaller, by default jpegoptim preserves quality, but can recompress using more lossy ratio, if size does matter.

    ~ cheers

  6. Great Mini-How-To, thank you.

    I think there is one point, the tool could do better. It should move backups to “image_original.jpg” instead of “image.jpg_original”. Many Tools don’t use a database (like Unix file) to determine the filetype but go just for the extension, for the same reason a index.php.BAK or a index.php~ are suddenly readable in plaintext in your docroot.

  7. John

    Or just optimise in Photoshop?

  8. Adrian Marcu

    Or you can remove the exif before uploading, with “jhead -purejpg %1″.

  9. as well as privacy concerns – stripping the meta data also reduces the file size – though id suggest biting the bullet and using PS for this I got an order of magnitude again using PS vs the tool suggested in firebug.

  10. sorry for my ignorance but I didn’t realise images had metadata!
    what will this actually strip interms of ‘privacy concerns’?
    Any help would be appreciated

  11. @John, that’s not very useful for the average Ubuntu/Linux user, it’s even less useful if you’re using this as part of an automated script.

  12. Henkie

    Why is everything ubuntu-based nowadays? For instance, the google talk plugin was first released for ubuntu instead of “any Linux”.

    People running Fedora can use:
    sudo yum install perl-Image-ExifTool
    exiftool -all= *.jpg

    For OpenSUSE, use yast to install exiftool.

  13. Maurice, if you want to reduze filesize in on the console, you could get “convert” from the imagemagick lib which can do the trick as well, it is really powerful:

    http://www.imagemagick.org/script/command-line-processing.php
    http://www.imagemagick.org/script/convert.php

    It is as easy as

    convert -scale 320x240 -quality 75% image_old.jpg image_new.jpg

  14. Although stripping exif data is also possible with imagemagick – i like the idea of automatically copying the JPGs.

  15. Rob

    @John,
    First, you need to buy Photoshop if you don’t have it. Second, this small program is free. Third, this program can operate on multiple images at once, with benefits.

  16. jeff hall

    Opitmising the image in e.g. photoshop still leaves the matadata.
    Metadata can sometimes be useful in a dispute over the copyright of an image – particularly with plagarists who are unaware of that metadata information. So i was wondering why would you want to remove it?

  17. guillemsola

    Imagemagik is a cross platform project that does the trick and can even do much more things.

  18. A lot of people don’t realize, think or care that all this data is embedded in there.

  19. Or you can use exiv2 and strip all the other metadata at the same time IPTC, XMP and EXIF:

    exiv2 -d a *.jpg

  20. Stripping out metadata is really important for any site that generates user thumbnails. I’ve seen 32px JPEG thumbnails that were 32 KB.

    Adding to Thorsten’s suggestion for ImageMagick, you can also strip metadata with ImageMagick’s “-strip” command.

    convert -scale 320×240 -strip -quality 75% image_old.jpg image_new.jpg

    I’ve used ImageMagick and Apache on Ubuntu to create a personal photo sharing site that automatically resizes images using a .htaccess callback to 50 line index.php file. I’d be happy to post the code if there’s interest.

  21. I would use ImageMagick for such purposes.

  22. Thank you this is a handy tip!

  23. Phil Harvey

    @Thorsten: exiftool changes the extension of the backup original file on purpose, specifically so the image is no longer recognized as a jpeg. Otherwise, subsequent processing passes by exiftool would also process the original image, which would be bad.

  24. I use Ubuntu and this should help me a lot. But what if on a certain time I’m on Windows? Is there any way to do that (I know there are many ways, I just want to know the most useful and easiest of them)?

  25. The benefit of doing this at command line instead of PS would be the ability to strip the metadata in bulk. If you have an photo collection with several hundred thousand images, stripping the meta data from all of them in a GUI would be the kind of work that drives people to develop drinking problems. With a little command line-fu it is a matter of a single command.

  26. Matt
    I thought that u only write about SEO on ur blog. But after reading this post, I see that u write technical also.

    But a question here:
    Isn’t this contrary to what you say ” Focus on one niche”.

    ATUL

  27. imagemagick -strip doesn’t work on PNG metadata. Yet.
    It will work in imagemagick 6.6.7

  28. Thank you for the useful information. This helps a lot.

  29. Extremely useful, thanks Matt. BTW, I’m also using more Ubuntu, and less Debian.

  30. As a pro photographer, I’d like to remind folks to not remove metadata on images that aren’t their own. This often includes copyright notice and licensing info. Tampering with that violates the DMCA. And just isn’t nice.

    Thanks :)

  31. I just do a print screen of the image and then import it into Photoshop/Gimp and resave it.
    As far as I know it does the same thing and is effective for the majority of uses.

Leave a Comment

Your email address will not be published. Required fields are marked *

*

If you have a question about your site specifically or a general question about search, your best bet is to post in our Webmaster Help Forum linked from http://google.com/webmasters

If you comment, please use your personal name, not your business name. Business names can sound salesy or spammy, and I would like to try people leaving their actual name instead.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

css.php