Gimp image optimization with Python plugins
Show Your Colors
As the third correction of raw images, I often adjust the white balance. If a digital photo does not exhaust the full range of possible pixel values from 0 to 255 for each of the three channels (red, green, blue), images often lack vibrancy and appear flat (Figure 4).
If you prefer brighter colors and higher contrast, you can fire up a useful tool in Gimp under Colors | Auto | White Balance; this adjusts the pixel values of the three channels so that their distribution in the histogram covers the entire intensity bandwidth. This doesn't always look good, but it sometimes gives boring pictures the necessary pizzazz (Figure 5).
However, my initial search for the corresponding Gimp function in the Procedure Browser and in the Plugin Browser was unsuccessful. But luckily, Gimp's source code on GitHub is visible to everyone (Figure 6), and a short search for the Automatic white balance
string in the repository showed that the corresponding Gimp procedure goes by the name of drawable_levels_stretch()
.
This function is again documented in the Procedure Browser and only requires the drawable of the image as a parameter. I quickly added the call at line 26 of Listing 2, and it became part of the image processing process.
One Step Forward, One Step Back
Gimp naturally treats the three actions of scaling, sharpening, and color correction of the image as three separate actions. If a user changes their mind afterwards and clicks on the Undo
menu entry, they would have to do this three times in a row, which is annoying, because they actually only initiated a single combined action via a mouse click in the menu. The solution is to call gimp_image_undo_group_start()
in line 10 and the corresponding ..._end()
in line 28.
They define all three intermediate actions as a single undo unit, so that Gimp will roll them back atomically, just like it will roll them forward as one step when asked to do so. Figure 7 shows that even Gimp's Edit menu now shows the last action not as the white balance (which was last to run), but as Sharpen and Scale, which is the name of the combined action we used in the plugin code for the whole enchilada to happen in one go.
I hope this issue's examples have shown that Gimp's Python API has access to all internal functions and that it is easy to bundle workflows consisting of many small steps, attach them to a menu and run them in one fell swoop. This eliminates drudgery for the user, saves time, and eliminates errors humans inevitably make.
Infos
- Listings for this article: ftp://ftp.linux-magazine.com/pub/listings/linux-magazine.com/222/
- Lanczos resampling: https://en.wikipedia.org/wiki/Lanczos_resampling
« Previous 1 2
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 Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
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.