Compress JPEG images with Lepton
Shrink It
![© Lead Image © Xavier_Gallego_Morell, 123RF.com © Lead Image © Xavier_Gallego_Morell, 123RF.com](/var/linux_magazin/storage/images/issues/2017/194/lepton-image-compressor/po-26278-123rf-xavier_gallego_morell_123rf-tiny_brick_wall_resized.png/688483-1-eng-US/PO-26278-123RF-Xavier_Gallego_Morell_123RF-Tiny_Brick_Wall_resized.png_medium.png)
© 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.
![](/var/linux_magazin/storage/images/issues/2017/194/lepton-image-compressor/figure-1/688486-1-eng-US/Figure-1_large.png)
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.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.