Posts Tagged EXIF

Bulk Convert jpg to HEIC (with metadata!)

Want to bulk-convert jpg files to the more space-efficient HEIC format, and preserve your metadata while you’re at it?

Here’s a few commands to do just that.

This will assume all images in the current directory have ‘.jpg’ extensions, and may have an ‘.XMP’ sidecar file with metadata in it. Most photo libraries, including macOS Photos, have an option to export files with metadata in an XMP sidecar file. Doing this is highly recommended, as it will pull in metadata from the sidecar file that may not be embedded in the original image.

These bash one-liners were run using bash 3.2.57. These also require the latest (as of this writing) ExifTool and ImageMagick installed and on your path. If you’re using macOS, ExifTool and ImageMagick can be installed using Homebrew with the following commands:

brew install exiftool
brew install imagemagick

Once you have those, you’re ready to go.

First, convert all the files to HEIC:

for x in *.jpg; do echo "$x"; magick "$x" "${x%.jpg}.HEIC"; done 

Next, import the metadata from each source image:

for x in *.jpg; do echo "$x"; exiftool -overwrite_original -tagsFromFile "$x" -all:all "${x%.jpg}.HEIC"; done

Last, import any additional metadata from XMP sidecar files, if they exist:

for x in *.jpg; do echo "$x"; exiftool -overwrite_original -tagsFromFile "${x%.jpg}.XMP" -all:all "${x%.jpg}.HEIC"; done

That’s it!

, , , , , ,

Leave a comment

How to retrieve EXIF data from the command line in Ubuntu Linux

If you want to make use of the EXIF data stored in a JPEG (.jpg or .jpeg) or TIFF (.tif or .tiff) file from the command line in Ubuntu Linux — or most other Linux variants — here’s how.

This was tested on Ubuntu 11.10 (Oneiric Ocelot).

First, you will need to have imagemagick installed to provide the identify command.

sudo apt-get install imagemagick

Next, you can retrieve the data on an image with the following example:

identify -verbose /usr/share/backgrounds/WildWheat_by_Brian_Burt.jpg

If you want just the EXIF data, you can use something like the following:

identify -verbose /usr/share/backgrounds/WildWheat_by_Brian_Burt.jpg | grep "exif:"

, , ,

Leave a comment

Bash script to automatically sort photos into folders based on EXIF data for Ubuntu Linux

If you — like me — take a lot of digital pictures, you probably have a hundred folders full of images on your hard drive or external drives, and not nearly as sorted as you would like them to be. you have probably gotten to the point that you don’t know what’s in them or can’t find an image when you’re looking. I had around 10,000 images in over a dozen folders spanning 5+ years, and I had no intention of even trying to sort them manually :) So I wrote this script.

The following script was written in bash on Ubuntu Linux and automatically sorts your images into directories based on the date and time the photo was taken. How does it do this? By making use of the EXIF data your digital camera stores inside the image. The date and time the photo was taken is stored in that EXIF data. When an image doesn’t have EXIF data (such as when it was downloaded from the Internet, or taken from a camera that doesn’t support adding EXIF data), it will use the files last-modified time.

First, this should be run in the top-most directory of wherever your pictures are stored. If you have pictures/foldername/somepics/ and pictures/anotherfolder/morepics, run it from your pictures/ directory.

There are quite a few opportunities to improve this script — and some cautionary notes as well — marked within the script with FIXME tags. I’m already finished sorting my images, but anyone is welcome to contribute suggestions and improvements, which I’ll look into incorporating the next time I’m using this. You are welcome to include any suggestions or code improvements in the comments below using <code> and/or <pre> tags.
Usage: Copy the script into a file, editing options where appropriate, and save it. Make it executable and run it from the command line or window, from the directory where your pictures are stored. No command-line arguments. Back up your stuff first :)

UPDATE: Because WordPress keeps mangling this code, it has been moved to github, here.

Questions, comments, or feedback can be left in the comments below, or please use the contact form. Thank you!

, , , ,

Leave a comment