Fast image processing with ExactImage
Less is More
Automate image processing with this quick and easy-to-use photo tool suite.
Anyone processing images automatically in batch mode needs lean, easy-to-use tools. The program of choice is usually convert
from the ImageMagick suite [1]; however, this program has some drawbacks. In particular, convert
does not necessarily impress with its stability. This is not typically a major issue, but in case of complex command lines, you might see the program calls abort with a (mostly incomprehensible) error message and produce incorrect results, or even none at all.
In fact, even composing a command line for convert
proves to be a task that should not be underestimated: The program supports no fewer than 300 different options that often exhibit strange syntax. Many options serve very specific tasks and require experience and a great deal of background knowledge on the part of the user – for example, do you know offhand what calling convert
… -resize 200\>x300^
… would give you?
Many users also complain about the lack of effectiveness of the ImageMagick tools. The programs are not especially quick, nor do they deliver particularly brilliant results – in part because of the massive functional diversity, which is often not needed.
The GraphicsMagick [2] suite is an attempt to resolve these issues; another competitor goes by the name of ExactImage [3]. Both provide only a subset of ImageMagick's repertoire and restrict their feature set to the most important functions.
What differences exist between the three suites? Although ImageMagick comes with almost 20 different programs, GraphicsMagick is a single program – along with three configuration tools; ExactImage provides seven tools (Table 1).
Table 1
ExactImage Programs*
Program | Function |
---|---|
|
Reads barcodes |
|
Groups multiple images as a multipage TIFF |
|
Universal converter; counterpart to |
|
Identifies image files; counterpart to |
|
Detects images of empty pages |
|
Uses hOCR files to generate searchable PDFs |
|
Optimizes image files for archiving |
*Additionally, |
Although GraphicsMagick tries to cover most of ImageMagick's functions, the tiny ExactImage suite delivers only one universal tool (econvert
, as a counterpart to convert
), as well as some programs for very specific tasks, such as reading barcodes and detecting blank pages.
And, Action!
Like convert
from the ImageMagick tools, econvert
is the main tool when it comes to creating new images from existing ones. The syntax follows the structure:
$ econvert -i <input file> -<option> ... -o <output file>
The main thing here is to pay attention to the correct order of the individual components; otherwise, econvert
(just like convert
) might ignore the specified options. Starting with a single input file, you can use multiple switches -<option>
-o <output file>
to create as many output files as you like on a single command line.
The way the ExactImage tools work is completely controlled by various options, just like ImageMagick (Table 2). ExactImage supports only a subset of the available image formats, and they differ in terms of input and output (Table 3). That said, ExactImage does support the main image formats to a large extent.
Table 2
Important Options
Option | Function |
---|---|
|
Compression method for output, say, |
|
Defines the quality as a percentage, default: 75 |
|
Resolution in X and Y direction |
|
Defines the width and height of the output file for raw image formats |
|
Scales by the stated factor |
|
Crops the image to the specified section |
|
Automatic cropping (from the bottom edge) |
|
Mirrors vertically |
|
Mirrors horizontally |
|
Rotates the image through the stated angle |
|
Adjusts the brightness (-1 to +1) |
|
Adjusts the contrast (-1 to +1) |
|
Adjusts the saturation (-1 to +1) |
|
Adjusts the lightness (-1 to +1) |
|
Adjusts the hue (-360 to +360) |
|
Creates a negative |
|
Adjusts the gamma |
|
"Normalizes" the colors in the image |
|
Converts images to one of the color models |
|
Generates shade as per Floyd-Steinberg |
|
Generates shade as per Riemersma |
|
Gaussian blur |
|
Finds edges |
|
Sets the drawing color |
|
Sets the background color |
|
Sets the font |
|
Outputs the text at the specified position at the specified size |
|
Rotates texts |
|
Line thickness |
|
Draw line between specified points |
Table 3
Image Formats
Abbreviation | Image Format |
---|---|
BMP |
Windows primitive bitmap format |
Digital Camera RAW |
Raw data formats supported by DCRAW |
Encapsulated PostScript |
Single-sided PostScript |
GIF |
The legacy bitmap format |
JPEG |
Classic JPEG |
JPEG2000 |
The new JPEG variant |
OpenEXR |
HDR bitmap format with up to 32-bit floats per channel |
PBM |
Portable bitmap format |
PCX |
Picture Exchange, widespread exchange format |
|
Write-only, with embedded JPEG and JPEG2000 and fonts |
PNG |
Standard bitmap format |
PostScript |
Write-only, with embedded JPEG |
RAW |
Raw image files |
SVG |
Scalable vector graphics, read-only |
Targa, TGA |
Truevision Advanced Raster Graphics Array, up to 32 bits per channel |
TIFF |
The classic standard |
XPM |
X Window bitmaps (mainly for icons) |
When scaling with --scale
, the algorithm automatically determines which method to use. If you are not satisfied with the results it delivers, you can set the method yourself. The options in this case are:
--bicubic-scale
--bilinear-scale
--box-scale
--ddt-scale
--nearest-scale
Moreover, the --thumbnail
fast filter generates thumbnails.
The example in Listing 1 once again illustrates the use of econvert
. It produces three different output files from one input file.
Listing 1
Using econvert
Who Are You?
The second important program from the ExactImage suite is edentify
, which is used to identify the format of an image. The example shown in Listing 2 is deliberately difficult: Identifying raw data formats is already a challenging task, and this is again aggravated by the DNG created by the conversion. Listing 3 shows the way ImageMagick handles this job with identify
.
Listing 2
Using edentify
Listing 3
Using identify
Although edentify
provides reasonably correct information and does not even try to guess file sizes, it outputs many error messages. ImageMagick's identify
takes a different approach. First, it converts the raw data to a bitmap format, which it then analyzes.
Whether this approach makes sense is doubtful. The file sizes specified by identify
are totally wrong because they relate to the bitmap files generated by the conversion, rather than the originals. Evaluating a DNG as a TIFF can be seen as reasonably correct, because DNG was designed as an extension of the TIFF standard.
The ability to display specific information about images with edentify
is interesting. This is achieved by specifying a "format string" as an argument for the -f
option. For example, -f "%f"
gives you the file name, -f "%w"
the width, and so on. Table 4 summarizes the most important variants. To connect several strings, you can use \t
(tabulator), \n
(newline) or \r
(carriage return).
Table 4
Format Strings
Abbreviation | Meaning |
---|---|
|
Directory |
|
Full file name |
|
File name without extension |
|
Path |
|
Width |
|
Height |
|
Color depth per channel |
|
X resolution |
|
Y resolution |
|
Image depth |
All told, edentify
offers only limited features; again, you might need to resort to ImageMagick's identify
.
Utilities
The other programs from the ExactImage suite are more specialized. For example, bardecode
automatically evaluates scanned bar codes; this still works even with relatively poor images. The e2mtiff
tool merges multiple images into a multipage TIFF file:
$ e2mtiff x1.jpg x2.png ... -o <out>.tiff
Multipage TIFFs are not particularly widespread nor particularly popular on Linux. However, Gimp can open and edit them. Figure 1 shows what a multipage TIFF looks like in Gimp when you load it. You can now individually edit the pages, which exist as layers (Figure 2), or convert them to new images by dragging them over the toolbox with the mouse.
The optimize2bw
program prepares scanned pages to improve their suitability for subsequent processing with OCR. The empty-page
program detects blank pages, so you can discard them up front. Finally, hocr2pdf
is the probably the most-used tool in the ExactImage program suite.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.
-
Fedora 41 Released with New Features
If you're a Fedora fan or just looking for a Linux distribution to help you migrate from Windows, Fedora 41 might be just the ticket.
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.
-
System76 Unveils an Ampere-Powered Thelio Desktop
If you're looking for a new desktop system for developing autonomous driving and software-defined vehicle solutions. System76 has you covered.
-
VirtualBox 7.1.4 Includes Initial Support for Linux kernel 6.12
The latest version of VirtualBox has arrived and it not only adds initial support for kernel 6.12 but another feature that will make using the virtual machine tool much easier.
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.