JPEG Renaming and Loss-Free Processing EXIF TRICKS
Total Page:16
File Type:pdf, Size:1020Kb
COVER STORY Image Processing with EXIF JPEG renaming and loss-free processing EXIF TRICKS You can rename and modify JPEG files without touching the graphics by manipulating settings in the file header. www.sxc.hu BY MARTIN STEIGERWALD he Exchange Image File (EXIF) data is included with image file formats tings such as the date and time of cre- format is a standard developed such as JPEG and TIFF, as well as with ation, the exposure time, the aperture Tby the Japan Electronic Industry audio formats such as RIFF. Depending setting, the exposure program, the size, Development Association (JEIDA) that on the model and make of your camera, the resolution, and the orientation of the lets digital cameras store meta-informa- the meta-information stored in the image. tion in the header of an image file. EXIF header of the image file can include set- Linux provides several tools for ma- nipulating EXIF data directly. Directly Table 1: EXIF Applications manipulating the metadata associated with an image file saves time, promotes Application EXIF Support Loss-free Rotation and Mirroring automation, and, in some cases, pre- Digikam 0.7.2, Photo management Load, display, but not save In the drop-down for the image, also automatically based on EXIF vents the data loss that would occur information with graphic manipulation. This article Eye of Gnome 2.8.2, Image Viewer Load, display, and save No describes some techniques for using Feh 1.3.4, Image viewer No Via File | Edit in Place. EXIF infor- EXIF metadata to rename and manipu- mation is lost late JPEG images. Gimp 2.2.7, Image manipulation Save No tool Using EXIF Data Gqview 2.0.1, Image viewer Load and display Via Edit | Rotate… Several graphic viewers and editors offer Gwenview 1.2.0, Image viewer Load, display, and save; Via Edit and Plugins / Images, automatic rotation in viewer automatically based on EXIF access to EXIF information (Table 1). information You can even view EXIF settings in Kpaint 0.6.2, Paint program No No Konqueror. To view EFIXF data in the Kolourpaint 1.4.1, Paint program No No Konqueror browser, right click on an Kuickshow 0.8.7, Image viewer Load, display, automatic No image file in the Konqueror window and rotation on viewing, not select Properties. The EXIF information on saving is located below Meta Info (Figure 1). 38 ISSUE 61 DECEMBER 2005 WWW.LINUX - MAGAZINE.COM Image Processing with EXIF COVER STORY Figure 1: Konqueror can display EXIF infor- Figure 2: Krename allows you to rename photos based on the exposure date. The program mation for photos. help explains the arcane templates. You can add a comment for the image Gwenview and Kuickshow viewers also Image, although the image orientation is file that will be stored with the EXIF in- support this standardized dialog. not included. You can add a comment, formation in the file header. The image If you prefer Nautilus, again you can but Nautilus will store it in below orientation in Orientation is a numerical select Properties in the context menu. ~/.nautilus/metafiles/ rather than in the value (see Table 2). The KDE-based Nautilus displays the EXIF values below image file. ADVERTISEMENT WWW.LINUX - MAGAZINE.COM ISSUE 61 DECEMBER 2005 39 COVER STORY Image Processing with EXIF EXIF information. Add a number of files to the program window and type $-[jpgCreationDate]-[jpgCreationTime], for example. You can also use other EXIF and JPEG information, such as com- ments or the JPEG quality. Clicking on Functions in the Filename tag gives you the placeholders. Krename uses the date and time format defined in the KDE con- trol center by default. A template such as $-[7-{[jpgCreationDate]}]-[4-5 {[jpgCreationDate]}]-[1-2{[jpgCreation Date]}]-[jpgCreationTime] sets the format to YYYY-MM-DD for improved sorting (Figure 2). Loss-Free Another example of an easy fix through EXIF data manipulation is the problem of picture orientation. If you have a cam- era with an orientation sensor, you will typically want to view your photos the Figure 3: Jpegtran supports loss free image cropping. If the selection to be cropped does not right way up. Whereas the Kuickshow sit exactly on a JPEG block border, Jpegtran scales the selection by the required number of viewer parses the orientation to auto- pixels. matically display images the right way, Gwenview first loads and displays the Linux also provides command-line The Jhead utility [3] helps you do this: image before rotating it. Kview, Eye of utilities for managing EXIF data. Two of jhead -n%Y-%m-%d_%H-%M-%S *.jpg Gnome (EOG), Gqview, Feh, Display (in the tools, exiftags [1] and metacam [2] renames the JPEG images in the current ImageMagick), and Showfoto (in Digi- offer a wide range of command-line op- directory. The format is flexible and easy kam) do not automatically rotate images. tions. Some distros do not include these to modify, but make sure you do not in- This means you have to rotate images utilities, although an RPM package is sert a blank after the -n option. manually, or use a tool to do it. Unfortu- available for exiftags. As you’ll learn in The -nf option lets you give the image nately, this step introduces a potential this article, other EXIF-related utilities, a name that isn’t mainly made up of source of error. The JPEG format is lossy such as Jhead, Krename, and Jpegtran numbers. Digital cameras typically use and can help you save space, but you are also useful for certain specific tasks. a format that comprises figures. This is lose some image data when you load, Jhead’s way of preventing users from manipulate, or store a JPEG image. De- Automatic File Renaming using -n to rename files they have al- pending on the quality level, this loss Digital cameras are notorious for provid- ready manually renamed. The -ft option will lead to artifacts sooner or later. ing non-intuitive names for images. By sets the file date to the exposure date. On a brighter note, a few programs editing the EXIF data, you can add date The KDE Krename tool [4] also pro- support loss-free JPEG image manipula- and time information to the file name. vides the ability to rename files based on tion. These tools use the internal struc- ture of the JPEG format to achieve this. Table 2: Image Orientation One step in the JPEG process is to divide the image into eight-by-eight, 16-by- EXIF Value 1st row in image 1st column in image Example eight, or 16-by-16 blocks of pixels. This 1 top left means that programs can only perform loss-free manipulation of images of a 2 top right size that is a multiple of eight-by-eight, 3 bottom right 16-by-eight, or 16-by-16 pixels (that is, 1600 x 1200 or 3072 x 2048). 4 bottom left A few basic image manipulation steps are always loss-free: for example rotat- 5 left top ing, mirroring and cropping of images, 6 right top or conversion to monochrome (although this discards the color information.) 7 right bottom If your camera has a sensor, the EXIF information can help you rotate images 8 left bottom automatically. For example, jhead -auto- 40 ISSUE 61 DECEMBER 2005 WWW.LINUX - MAGAZINE.COM Image Processing with EXIF COVER STORY rot *.jpg rotates all the JPEG images in will give you a loss-free image if the size 16, Jpegtran moves the start coordinates the current directory based on their EXIF is right, but if not, you are better off up left by the required eight pixels. data. To do this, the orientation value is using Djpeg and Cjpeg, which are both If you modify a JPEG image using an automatically set to 1 for “top left” after lossy. image manipulation tool and save it in rotating. Fortunately, Jhead only does JPEG format, you should look to use a this to photos that actually need rotat- GUI-based tool that preserves the EXIF information. ing, in contrast to Exiftran. Loss-free manual rotation and mirroring Gimp has a Save EXIF Data entry in the You can use Exiftran to rotate images is also supported by the viewers Gwen- JPEG options dialog; the option is en- manually. exiftran -i -9 image.jpg rotates view, Gqview (both assuming that Jpeg- abled by default. In contrast, Kolour- an image through 90 degrees. Use -1 to tran is installed), and Feh. For example, paint and Kpaint both discard EXIF in- rotate 180 degrees, and -2 to turn the you can rotate images while viewing a formation on saving. ■ image 270 degrees. The -f option mirrors slideshow. Digikam uses the Kipi plugin the image horizontally, and -F vertically. for more functionality. If the Kipi plugin INFO The Jpegtran utility can give you loss- for loss-free JPEG image manipulation is [1] Exiftags: http:// johnst. org/ sw/ exiftags/ free manipulation of images with sizes installed and enabled, the drop-down [2] Metacam: http:// www. cheeseplant. that do not reflect the JPEG block sizes, menu for an image has the options Auto- org/ ~daniel/ pages/ metacam. html but it does so by ignoring the border, matic Rotation and Mirroring based on [3] Jhead: http:// www. sentex. net/ which leaves you with a bar at the EXIF Information, Rotate, Mirror and ~mwandel/ jhead/ edges. If you set the -trim option when Convert to Monochrome. [4] Krename: http:// www. krename. net/ running Jpegtran, the tool removes the border, but this is not loss-free. Cropping If you set the -perfect option, Jpegtran Jpegtran also supports loss-free crop- Martin Steigerwald is a system ad- issues an error message if you attempt to ping.