Compress JPEG images with Lepton
Shrink It

© Lead Image © Xavier_Gallego_Morell, 123RF.com
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
Direct Download
Read full article as PDF:
Price $2.95
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Find SysAdmin Jobs
News
-
Kubuntu Focus Announces XE Gen 2 Linux Laptop
Another Kubuntu-based laptop has arrived to be your next ultra-portable powerhouse with a Linux heart.
-
MNT Seeks Financial Backing for New Seven-Inch Linux Laptop
MNT Pocket Reform is a tiny laptop that is modular, upgradable, recyclable, reusable, and ships with Debian Linux.
-
Ubuntu Flatpak Remix Adds Flatpak Support Preinstalled
If you're looking for a version of Ubuntu that includes Flatpak support out of the box, there's one clear option.
-
Gnome 44 Release Candidate Now Available
The Gnome 44 release candidate has officially arrived and adds a few changes into the mix.
-
Flathub Vying to Become the Standard Linux App Store
If the Flathub team has any say in the matter, their product will become the default tool for installing Linux apps in 2023.
-
Debian 12 to Ship with KDE Plasma 5.27
The Debian development team has shifted to the latest version of KDE for their testing branch.
-
Planet Computers Launches ARM-based Linux Desktop PCs
The firm that originally released a line of mobile keyboards has taken a different direction and has developed a new line of out-of-the-box mini Linux desktop computers.
-
Ubuntu No Longer Shipping with Flatpak
In a move that probably won’t come as a shock to many, Ubuntu and all of its official spins will no longer ship with Flatpak installed.
-
openSUSE Leap 15.5 Beta Now Available
The final version of the Leap 15 series of openSUSE is available for beta testing and offers only new software versions.
-
Linux Kernel 6.2 Released with New Hardware Support
Find out what's new in the most recent release from Linus Torvalds and the Linux kernel team.