Once in a while you need to remove EXIF data from your pictures so that you can upload them to the Internet safely. While there are a few GUI tools to do that, they are not very convenient. I.e. it’s hard for them to combine portability, batch processing, file selection capabilities and scripting potential. Searching for universal command line tool, preferably native to popular flavors of UNIX resulted in nothing. So I’ve decided to investigate and found a solution that meets my criteria (read Q&A at the end of this post before commenting).
First things first we need Perl. It’s available in many default installations of Linux distributions, BSDs, OSX and even Solaris (which nobody uses anymore). If you don’t have it, install appropriate package(s).
In next steps I assume you are working as regular, unprivleged user. I strongly advise against working as root for non-root purposes, ever. Security is one reason but system hygiene is no less important. If something goes wrong during Perl’s package management, you may end up with incomplete/broken libraries. Such things are handled easier when contained within unprivileged user account.
If you’re using OSX like me (10.9 at the moment of writing this) you may need to install XCode. I’m not sure, I don’t have Mac computer without it for testing. XCode is free anyway and it may provoke you to become programmer, so it’s worth installing.
Launch cpan – it’s Perl’s package manager. If you’ve never used it, it will ask you some questions – if you don’t like reading and understanding what’s going on just press enter until you see prompt as below.
Good. If you exit (^D) cpan, it will display a few environmental variables for you to add to your .profile or .bash_profile (or your shell’s equivalent). Add them and source this rc file. This is an example (your values will be different):
*** Remember to add these environment variables to your shell config and restart your shell before running cpan again *** export PERL_LOCAL_LIB_ROOT="$PERL_LOCAL_LIB_ROOT:/Users/demouser/perl5"; export PERL_MB_OPT="--install_base /Users/demouser/perl5"; export PERL_MM_OPT="INSTALL_BASE=/Users/demouser/perl5"; export PERL5LIB="/Users/demouser/perl5/lib/perl5:$PERL5LIB"; export PATH="/Users/demouser/perl5/bin:$PATH";
Now start cpan again and search for Image::ExifTool. I’m not sure if this module will be around forever, so if this command fails you can stop reading and search for another how-to.
cpan> i /^Image::ExifTool$/ Module id = Image::ExifTool CPAN_USERID EXIFTOOL (Phil Harvey ) CPAN_VERSION 9.27 CPAN_FILE E/EX/EXIFTOOL/Image-ExifTool-9.27.tar.gz INST_FILE (not installed)
If output is similar to what you see above, continue with installation:
cpan> install Image::ExifTool
cpan will do it’s work and should end with something like this:
Appending installation info to /Users/demouser/perl5/lib/perl5/darwin-thread-multi-2level/perllocal.pod EXIFTOOL/Image-ExifTool-9.27.tar.gz /usr/bin/make install -- OK cpan>
Excellent. Now not only you have Perl libraries necessary to create your own tools for EXIF manipulation but also…
$ which exiftool /Users/demouser/perl5/bin/exiftool
…the exiftool itself, ready for use. The fine manual has a few examples of usage. Reading EXIF data:
$ exiftool -a -u -g1 DSC00835.jpg | grep Lens Lens Info : 18-70mm f/3.5-5.6 Lens Model : DT 18-70mm F3.5-5.6 Lens ID : 40 Lens Info : 18-70mm f/3.5-5.6 Lens : DT 18-70mm F3.5-5.6 Lens ID : Minolta/Sony AF DT 18-70mm F3.5-5.6 (D)
Deleting all EXIF data (Warning – make sure you have backup copy before proceeding! exiftool creates backup file with _original extension but play safe):
$ exiftool -all= DSC00835.jpg 1 image files updated
That’s it. No asking for confirmation, no fancy buttons to click. Read the manual for detailed description of every option. Obviously I can’t guarantee that exiftool will work as advertised but it didn’t fail me yet. I hope you’ll find it useful too.
For advanced readers: use Perl, WWW::Mechanize and Image::ExifTool to create web spider which will read dates and locations from every available picture on a given website (e.g. blog) and print report on discovered data. Additional points for presenting it as a map overlay.
Question: Why not use exiftool package from the actual author of these Perl modules?
Answer: This may sound paranoid but I don’t like the idea of installing precompiled software from untrusted sources if this involves using root password (e.g. sudo or via OS package management). If I can accomplish a task without elevating privileges to 0:0, then this is the way I choose.
Question: Why not use one of programs from OSX App Store (which is curated by Apple)?
Answer: Why should I pay 4-8EUR for something I can have free or happily code myself in 20-30 minutes?
Update: I am aware of sips command in OSX (think --deleteProperty all).