### Jhead is a command line driven program for manipulating the non-image parts of Exif flavour JPEG files that most digital cameras produce.

Windows / Mac users: Jhead has no Graphical User Interface. Clicking on it with the mouse from Windows or Mac OS-X won't do anything for you - you have to use it from the Command prompt (or DOS prompt under Win95/98/Me)

### Jhead v2.6 program Features

- Extracting camera settings from Exif image files
- Able to set and/or adjust the Exif time field
- Manipulation (extrac, replace, regenerate) of Exif integral thumbnails
- Transplant Exif image header from one JPEG to another
- Edit JPEG comment fields
- Automatically rotate images upright (using jpegtran) according to "orientation" tag.
- Manage running programs on large batches of Jpegs and restoring Exif header information afterwards.
- Display embedded GPS info (if present)

### General metadata options

-te <name> | Transplant Exif header from image <name> into specified image. This option is useful if you like to edit the photos but still want the Exif header on your photos. As most photo editing programs will wipe out the Exif header, this option can be used to re-transplant them back in after editing the photos. Like the '-st' option, this option uses a 'relative path', which is useful for doing a batch of photos at a time. For example, if you have a directory full of digital camera photos, before editing them, you could copy them into the subdirectory 'originals. Then edit them (or batch convert them using mogrify). After editing, you can put the original Exif headers back in to the whole directory of images at a time using the incantation: jhead -te "originals\&i" *.jpg
-dc | Delete comment field from the JPEG header. Note that the comment is not part of the Exif header.
-de | Delete the Exif header entirely. This leaves comments in the comment section intact.
-du | Delete sections of jpeg that are not Exif, not comment, and otherwise not contributing to the image either - such as data that Photoshop might leave in the image.
-purejpg | Delete all JPEG sections that aren't necessary for rendering the image. Strips any metadata that various applications may have left in the image. A combination of the -de -dc and -du options.
-ce | Edit the JPEG header comment field (note, this comment field is outside the Exif structure and can be part of Exif and non Exif style JPEG images). A temporary file containing the comment is created and a text editor is launched to edit the file. The editor is specified in the EDITOR environment variable. If none is specified notpead or vi are used under Windows and Unix respectively. After the editor exits, the data is transferred back into the image, and the temporary file deleted.
-cs <name> | Save comment section to a file
-ci <name> | Replace comment with text from file.
-cl <comment> | Replace comment with comment from command line.

### Date / Time manipulation options

-ft | Sets the file's system time stamp to what is stored in the Exif header.
-n[<fmt-string>] | This option causes files to be renamed according to the Exif header "DateTimeOriginal" field. If the file is not an Exif file, or the DateTimeOriginal does not contain a valid value, the file date is used. Renaming is by default restricted to files whose names consist largely of digits. This effectively restricts renaming to files that have not already been manually renamed, as the default sequential names from digital cameras consist largely of digits. Use the -nf option to force renaming of all files. If the [fmt-string] is omitted, the file will be renamed to MMDD-HHMMSS. Note that this scheme doesn't include the year (I never have photos from different years together anyway). If a [fmt-string] is provided, the fmt-string will be passed to the strftime function for formatting. In addition, if the format string contains '%f', this will substitute the original name of the file (minus extension). A sequence number may also be included by including '%i' in the format string. Leading zeros can be specified. '%03i' for example will pad the numbers to '001', '002'... this works just like printf in C, but with '%i' instead of '%d'. If the target name already exists, the name will be appended with "a", "b", "c", etc, unless the name ends with a letter, in which case it will be appended with "0", "1", "2", etc. This feature is especially useful if more than one digital camera was used to take pictures of an event. By renaming them to a scheme according to date, they will automatically appear in order of taking when viewed with some sort of viewer like Compupic or AcdSee, and sorted by name. Or you could use the -ft option and sort by date. Some of the more useful arguments for strftime are:
%d | Day of month as decimal number (01 – 31)
%H | Hour in 24-hour format (00 – 23)
%j | Day of year as decimal number (001 – 366)
%m | Month as decimal number (01 – 12)
%M | Minute as decimal number (00 – 59)
%S | Second as decimal number (00 – 59)
%U | Week of year as decimal number, with Sunday as first day of week (00 – 53)
%w | Weekday as decimal number (0 – 6; Sunday is 0)
%y | Year without century, as decimal number (00 – 99)
%Y | Year with century, as decimal number
Example: jhead -n%Y%m%d-%H%M%S *.jpg This will rename files matched by *.jpg according to YYYYMMDD-HHMMSS For a full listing of strftime arguments, look up the strftime function. Note that some arguments to the strftime function (not listed here) produce strings with characters such as '/' and ':' that may not be valid as part of a filename on various systems.
-nf | Same as '-n' but renames files regardless of original file name.
-a | (Windows only option). Rename files with the same name but different extension as well. This is useful for renaming .AVI files based on exif file in .THM, or to rename sound annotation files or raw files with jpeg files. Use together with '-n' option.
-ta<timediff> | Adjust time stored in the Exif header by h:mm backwards or forwards. Useful when having taken pictures with the wrong time set on the camera, such as after travelling across time zones, or when daylight savings time has changed. This option uses the time from the "DateTimeOriginal" (tag 0x9003) field, but sets all the time fields in the Exif header to the new value. Version 2.0 and earlier only modified the "DateTimeOriginal" (tag 0x9003) field, but too many people thought that that was a bug. Examples: Adjust time one hour forward (you would use this after you forgot to set daylight savings time on the digicam) jhead -ta+1:00 *.jpg Adjust time back by 23 seconds (you would use this to get the timestamps from two digicams in sync after you found that they didn't quite align) jhead -ta-0:00:23 *.jpg Adjust time forward by 2 days and 1 hour (49 hours) jhead -ta+49 *.jpg
-da<date>-<date> | Works like -ta, but for specifying large date offsets, to be used when fixing dates from cameras where the date was set incorrectly, such as having date and time reset by battery removal on some cameras Because different months and years have different numbers of days in them, a simple offset for months, days, years would lead to unexpected results at times. The time offset is thus specified as a difference between two dates, so that jhead can figure out exactly how many days the timestamp needs to be adjusted by, including leap years and daylight savings time changes. The dates are specified as yyyy:mm:dd. For sub-day adjustments, a time of day can also be included, by specifying yyyy:nn:dd+hh:mm or yyyy:mm:dd+hh:mm:ss Examples: Year on camera was set to 2005 instead of 2004 for pictures taken in April jhead -da2005:03:01-2004:03:01 Default camera date is 2002:01:01, and date was reset on 2005:05:29 at 11:21 am jhead -da2005:05:29/11:21-2002:01:01
-ts<date-time> | Sets the time stored in the Exif header to what is specified on the command line. This option changes all the date fields in the Exif header. Version 2.0 and earlier only changed the "DateTimeOriginal" (tag 0x9003) field, but too many people thought this was a bug. Time must be specified as: yyyy:mm:dd-hh:mm:ss

### Thumbnail manipulation options

-dt | Delete thumbnails from the Exif header, but leave the interesting parts intact. This option truncates the thumbnail from the Exif header, provided that the thumbnail is the last part of the Exif header (which so far as I know is always the case). Exif headers have a built-in thumbnail, which is typically 240x160 and 10k in size. This thumbnail is used by digital cameras. Windows XP, as well as various photo viewing software may also use this thumbnail if present, but work just fine if it isn't.
-st <name> | Save the built in thumbnail from Jpegs that came from a digital camera. The thumbnail lives inside the Exif header, and is a very low-res JPEG image. Note that making any changes to a photo, except for with some programs, generally wipes out the Exif header and with it the thumbnail. I implemented this option because I kept getting asked about having such an option. I don't consider the built in thumbnails to be all that useful - too low res. However, now you can see for yourself. I always generate my thumbnails using ImageMagick (see end of this page). This feature has an interesting 'relative path' option for specifying the thumbnail name. Whenever the <name> contains the characters '&i', jhead will substitute the original filename for this name. This allows creating a 'relative name' when doing a whole batch of files. For example, the incantation: jhead -st "thumbnails\&i" *.jpg would create a thumbnail for each .jpg file in the thumbnails directory by the same name, (provided that the thumbnails directory exists, of course). Both Win32 and most Unix shells treat the '&' character in a special way, so you have to put quotes around that command line option for the '&' to even be passed to the program. If a '-' is specified for the output file, the thumbnail is sent to stdout. (UNIX build only)
-rt <name> | Replace thumbnails from the Exif header. This only works if the exif header already contains an exif header a thumbnail.
-rgt[size] | Regnerate exif thumbnail. 'size' specifies maximum height or width of thumbnail. I added this option because I had a lot of images that I had rotated with various tools that don't update the exif header. But newer image browsers such as XnView make use of the Exif thumbnail, and so the thumbnails would be different from the image itself. Note that the rotation tag also needed to be cleared (-norot option). Typically, only images that are shot in portait orientation are afflicted with this. You can use the -orp option to tell jhead to only operate on images that are upright. This option relies on 'mogrify' program (from ImageMagick) to regenerate the thumbnail. Linux users often already have this tool pre-installed. Windows users have to go and download it. This option only works if the image already contains a thumbail.

### Rotation tag manipulation

-autorot | Using the 'Orientation' tag of the Exif header, rotate the image so that it is upright. The program 'jpegtran' is used to perform the rotation. This program is present in most Linux distributions. For windows, you need to get a copy of it. After rotation, the orientation tag of the Exif header is set to '1' (normal orientation). The exif thumbnail is also rotated as of Jhead version 2.5. Other fields of the Exif header, including dimensions are untouched, but the JPEG height/width are adjusted. This feature is especially useful with newer digital cameras, which set the orientation field in the Exif header automatically using a built in orienttion sensor in the camera.
-norot | Clears the Exif header rotation tag without altering the image. You may find that your images have rotation tags in them from your camera, but you already rotated them with some lossless tool without clearing the rotation tag. Now your friendly browser rotates the images on you again because the image rotation tag still indicates the image should be rotated. Use this option to fix this problem. You may also want to regenerate the thumbnail using the -rgt option.

### Output verbosity control

-h | Displays summary of command line options.
-v | Makes the program even more verbose than it already is. Like DOS programs, and unlike Unix programs, Jhead gives feedback as to what it is doing, even when nothing goes wrong. Windows user that I am, when something doesn't give me feedback for 20 seconds, I assume its crashed.
-V | Print version info and compilation date.
-exifmap | Show a map of the bytes in the exif header. Useful when analyzing strange exif headers, not of much use to non software developers.
-se | Suppress error messages relating to corrupt Exif header structure.
-c | Concise output. This causes picture info to be summarized on one line instead of several. Useful for grep-ing through images, as well as importing into spread sheets (data is space delimited with quotes as text qualifier).

### File matching and selection

-model | Restricts processing of files to those whose camera model, as indicated by the Exif image information, contains the substring specified in the argument after '-model'. For example, the following command will list only images that are from an S100 camera: jhead -model S100 *.jpg I use this option to restrict my JPEG re-compressing to those images that came from my Cannon S100 digicam, (see the -cmd option).
-exonly | Skip all files that don't have an Exif header. This skips all files that did not come directly from the digital camera, as most photo editing software does not preserve the Exif header when saving pictures.
-cmd<command> | Executes the specified command on each Jepg file to be processed. The Exif section of each file is read before running the command, and re-inserted after the command finishes. The specified command invoked separately for each JPEG that is processed, even if multiple files are specified (explicitly or by wild card). I use this option to process whole directory trees of Jpegs from my digital camera with JPEGTRAN (Independent JPEG group) and Image-Magick's 'MOGRIFY' command without loosing the camera settings and other info stored in the Exif headers. JPEGTRAN is useful for lossless rotation, as well as for converting Jpegs to progressive Jpegs (also a lossless process, but results in typically 5% smaller files) I use mogrify for re-compressing the images I get from my Canon PowerShot S100 to 80% quality. The Canon Jpegs are either way too 'high quality' for the resolution, or are sub optimally encoded. Using mogrify to 80% produces no detectable loss in quality, with files about half the size. Example use: Having a whole directory tree of photos from my S100, I run the following commands: jhead -cmd "mogrify -quality 80 &i" -model S100 -r *.jpg jhead -cmd "jpegtran -progressive &i &o" -r *.jpg The first command mogrifies all Jpegs in the tree that indicate that they are from a Cannon S100 in their Exif header to 80% quality at the same resolution. This is a 'lossy' process, so I only run it on files that are from the Canon, and only run it once. The next command then takes all jpegs and converts them to progressive Jpegs. The result is the same images, with no discernible differences, stored in half the space. This only produces substantial savings on some cameras, such as the Canon S100. The newer S110 and S300 cameras are smarter about how they compress JPEG images, so re-mogrifying them may not give you any savings unless you crank the quality way down. However, turning them into progressive JPEG images is a lossless process that typically makes image files 5% smaller. Keeping the Exif header information is important to me, as I like to check things like the shutter speed for some of my photos, and my HTML index generating program uses the Exif tags to display the JPEG images in order of taking. Newer version of "mogrify" already preserve Exif information, so with some clever shell scripting, you could do these two steps without using jhead and still keep the Exif headers.
-orp -orl | Operate only on images with portrait (-orp) or landscape (-orl) aspect ratio. Please note that this is soley based on jpeg with and height values. Some browsers may auto rotate the image on displaying it based on the exif orientation tag, so that images shot in portrait mode are displayed as portrait. Howwever, the image itself may not be stored in portrait orientation. The -autorot and -norot options are useful for dealing with rotion issues.
-r | The recursive feature of version 1.0 never worked to my satisfaction, and I replaced it with my recursive file globbing code in the Windows version. See below.

### Bugs and Shortcomings

After jhead runs a program to rotate or resize an image, the image dimensions and thumbnail in the Exif header are not adjusted.

Modifying of Exif header data is very limited, as Jhead internally only has a read only implementation of the file system contained in the Exif header. For example, there is no way to replace the thumbnail or edit the Exif comment in the Exif header. There is also no way to create minimal Exif headers.

Some CANON digital SLR cameras fail to adjust the effective sensor resolution when shooting at less than full resolution, causing jhead to incorrectly miscalculate the sensor width and 35mm equivalent focal length. Jhead usually gets blamed for this bug, but it is in fact a camera bug, and jhead can't do much about it, and I'm not about to add camera bug specific hacks to it.

### Name globbing and recursive directories under Windows

Name globbing means matching wildcard patterns to actual file names. If you know what this term means, you are probably annoyed at how programs on Windows typically handle this. The Win32 version of this program goes beyond the pattern matching that Windows provides, and allows you to specify fancy UNIX-like patterns such as:

jhead c:\pix\199*\*\*.jpg

This program goes one step beyond beyond that in that "**" as a path component means any level of subdirectories. The invocation

jhead c:\**\*.jpg

will find ALL Jpegs files on the c: drive, including those in the root directory. The ** only works if it is the only part of that path component. For example, the path 'c:\a**\*.jpg' will not recurse. The '**' recursive expansion is ONLY supported on the Windows version. The code is in the module 'myglob.c', if you want to reuse it (I certainly intend to reuse that code for other applications). Under Unix, the shell's wildcard expansion is pretty decent already, and dealing with the convoluted nature of some Unix file layouts, doing better would have been much more of a challenge.

### Programs I use with Jhead

ImageMagick

I use the MOGIRIFY command from ImageMagick to do batch conversions and re-compresses of images. If you use Linux, you probably already have ImageMagick on your system (just type 'mogrify' at the command prompt to see if you have it). For Windows users, you have to download it from: http://www.imagemagick.org

Image Magick is one of those programs that preserves comment and Exif headers, although older versions do not.

JPEGTRAN

If you use Linux you probably also already have this program. For windows, it's hard to find a pre-built binary on the web. The Independent JPEG Group's website only has the source code.

There's a fancier version, with pre-built Windows binaries and a lossless cropping feature added at: http://sylvana.net/jpegcrop.

XnView

XnView is an excellent free graphical image browser, cross platform. I use it mostly instead of Compupic nowadays. Unlike Compupic, it makes use of jpeg thumbnails for the thumbnail view. On account of Xnview, I added options to fix or regenerate the thumbnails to jhead - this because copupic and jpegtran do not rotate the thumbail on doing lossless rotation, which can be annoying in Xnview.

CompuPic

I also use CompuPic to organize my photos. I especially like the built in lossless JPEG rotation feature (which also preserves the Exif header). This unfortunately is payware, but it's a pretty good program. Not free, but I ended up paying for it. I still prefer how CompuPic does some things over XnView.

wrjpgcom / rdjpgcom

You can use these programs to write and extract COM markers from JPEG images respectively. Although I always use my jhead program for this feature, the wrjpgcom and rdjpgcom programs are extremely simple and very suitable for use with perl or shell scripts to process lots of images. These programs are part of most Linux distributions as part of the libjpg package (along with jpegtran)

Jhead homeage: http://www.sentex.net/~mwandel/jhead
Last Updateed: April 29 2006