Compress JPEG images with Lepton
Shrink It
Lepton lets you compress your photo files to make room for more.
Although more sophisticated image formats have existed for some time [1], JPEG is still one of the most common. Whether you are working on a smartphone, compact camera, or professional photo device, you'll find an option for generating images in JPEG format. The flood of JPEG images caused by so many millions of users snapping photos actually sucks up lots of storage space on file hosting servers. This problem led cloud provider Dropbox [2] to look for a better way to store photo images. The result of this effort is the new Lepton image format, which reduces the space requirements for JPEG images by up to 25 percent. Lepton works losslessly, meaning the image remains exactly the same after you reconvert it (Figure 1). Dropbox says it has already applied the new format to 16 billion images and has thus saved multiple petabytes of storage space. The Dropbox cloud transparently converts JPEG images to Lepton format and changes them back into the original format as soon as someone accesses them.
Unlike JPEG, Lepton doesn't reduce the visible image – image reduction often results in known artifacts with JPEG. Instead, Lepton is designed to reduce the data needed for the image information using the Middle-out algorithm, a type of arithmetic coding that is also used in the VP8 video format. A Dropbox blog post provides a detailed technical explanation about how the Lepton format reduces the size of a JPEG file [3].
Installing Lepton
Dropbox has additionally released a tool, also called Lepton, that you can use to convert files to and from Lepton format. The Lepton compression tool is available under the Apache 2.0 license. Ubuntu, Debian, openSUSE, and several other Linux distributions provide Lepton packages. You can also download the source code from GitHub [4] and compile Lepton from source (Listing 1) If you choose to compile, you'll need the Git and Cmake tools, which you can install with:
sudo apt-get install git cmake
Listing 1
Compiling Lepton
The Lepton README [5] suggests a few other possibilities for obtaining Lepton, but Git or a package installation are likely the easiest options.
In Use
The Lepton syntax is pretty simple. For example, the command:
lepton image.jpg
converts the specified image into Lepton format. By default, the new file will have the original filename with the .lep
extension. The following command:
lepton filename.lep
extracts the original JPEG from a Lepton file.
If the output file already exists, Lepton doesn't overwrite it but instead creates a new file with an underscore (_
) at the end of the filename. You can also specify a filename for the output file.
During our tests, it became apparent that Lepton only processes images up to a maximum size of about 17MB; with larger images, the process aborts and the OOM SHORT_READ
error message appears. Fortunately, most JPEGs are smaller than 17MB.
Lepton generally works in multithreaded mode, employing multiple CPU cores if they are available. The -singlethread
switch disables the multithreading feature, which will significantly slow down the conversion process but will release more resources.
Lepton also has a server mode, which you can run with the command:
lepton -listen=2020
In this case, Lepton listens on TCP port 2020 for incoming connection requests (Figure 2).
Line 1 of Listing 2 sends a JPEG image to the server; the command in line 2 reconverts the file. In this example, the source and target are on the same computer.
Listing 2
Server Mode
Benchmark and Comparison
We compared Lepton with other compression tools by comparing the output file size for a 10MB JPEG file. Table 1 shows the results of various compression programs.
Table 1
Lepton vs Compression Tools
Action | Lepton | Bzip2 | Zip | Gzip | Convert WebP* |
---|---|---|---|---|---|
Compressed file size |
7.9 |
9.9 |
9.9 |
9.9 |
9.0 |
Compressing time (seconds) |
5.0 |
2.5 |
0.4 |
0.5 |
30.8 |
Decompressing time (seconds) |
2.1 |
0.9 |
0.09 |
0.10 |
2.4 |
* WebP works losslessly. |
As you can see in Table 1, not a single conventional compression algorithm succeeded in significantly shrinking a JPEG without losing quality. Lepton, however, was able to shrink the file, although it managed just 2 MB/s – far less than the advertised 5 MB/s encoding rate.
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
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
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.