Batch processing image files with imgp
Rapid Resizer
In no time at all, imgp can change the resolution of images, as well as convert files from PNG to JPEG, remove metadata, and rotate images.
Suppose you have hundreds or even thousands of photos that you want to present on a web page. If the images use the original camera resolution, they could severely slow down or even paralyze a website populated with this data. Optimizing the images can save bandwidth on the network and space on the storage medium.
With a large number of images, a batch processing tool such as imgp
[1] comes in handy. The command-line tool, formerly known as imgd
and written in Python, provides functions for resizing images in JPEG and PNG formats, as well as converting from PNG to JPEG, rotating the images, and removing metadata.
Even with thousands of files, imgp
does its job at lightning speed. The developer, Arun Prakash Jana, achieves this through multicore processing, an adaptive algorithm, and the Python Pillow library [2].
On processors that support single instruction, multiple data (SIMD) [3], you can use Pillow-SIMD [4] as an alternative to further speed up processing. In testing on an external hard disk with a USB 2 connection, Jana claims to have converted 8,823 images of different resolutions (with a total size of 4.5GB) to a resolution of 1366x1000 pixels in about eight minutes, with the resulting total size dropping to 897MB.
Easy Access
To install imgp
on a current distribution, you can simply use the package manager in most cases. The current version 2.8 is available on Arch Linux, CentOS, Debian Testing and Unstable, Devuan, Fedora, openSUSE Leap 15.3, Ubuntu 21.04, and others.
If your distribution ships with an older version of imgp
, install the packages from GitHub for DEB and RPM-based distributions or build the package from the source code [5]. Python 3.5 or newer is required. The nnn
[6] terminal file manager, also developed by Jana, offers batch conversion using imgp
as a script. (Jana is also the developer of another useful tool, googler
[7]).
Using imgp
's options, you can resize image files by specifying a percentage or a resolution. You can also rotate the image clockwise by a freely selectable angle, optimize images to save space, convert PNG to JPEG, delete Exif metadata, and more.
Options
To test out imgp
's capabilities, we tried out various imgp
command-line options on 65 vacation photos taken with a smartphone. The image sizes ranged from around 2 to 5MB, with a total size of 215.7MB. The tests were run on a PC with a Ryzen 7 3700X CPU with 32GB RAM.
If you enter imgp
at the command line without specifying any other parameters, the help page (Figure 1) loads with a list of all the options for manipulating the size or orientation of an image. As usual, imgp
assumes the current directory as the source unless you specify a different source. However, you can also process multiple sources in a single command.
Amazingly Fast
As the simplest test case, we entered the following command
imgp -x 1024x768
in the directory containing the 65 image files. This command converts all the images (with various resolutions) to 1024x768 pixels. The entire process took 1.29 seconds in the test and reduced the folder size from 215.1MB to 8.4MB (Figure 2). Listing 1 shows the command structure for processing multiple folders and files simultaneously.
Listing 1
Processing Multiple Sources
imgp -x 1024x768 ~/images/image1 ~/photos/image2 ~/pictures/
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
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.