神刀安全网

How To Quickly Optimize Jpeg Images on Linux

Let’s say you need to compress and optimize a JPEG image on Linux.

How do you do it?

You might reach for a GUI app, like GIMP, and play around with settings.

But that requires effort.

In this post we’re going to look at using a command line tool to effortlessly compress images on Linux.

If you don’t like the command line try the small image optimization app ‘Trimmage’, which provides a GUI front-end for jpegoptim (and pngcrush ).

How to Install jpegoptim on Ubuntu

First things first: let’s get the tool installed on your Linux machine.

As jpegoptim is a command line app we’ll show you how to use the command line to install it. This is entirely optional; you can also install the app using the Ubuntu Software Center (or a similar package management tool).

Open a new Terminal session and enter the following command, followed by your password as prompted:

sudo apt-get install jpegoptim

The app is tiny so won’t take long to install. Once it has it’s ready to use.

Using Jpegoptim on Ubuntu

How To Quickly Optimize Jpeg Images on Linux

Jpegoptim is a small utility that can compress and optimize JPEG files without significant lose in quality — but a notable difference in file size.

Compression can help save on bandwidth (if using images on a website) and make sending emails a bit faster (if you have a slow connection).

Using the tool couldn’t be simpler.

The default command optimizes your jpg images using maximum/lossless settings to offer the best image quality. To process an image you run the ‘jpegoptim’ command followed by the location of the image you wish to compress.

For example,  I have a 1.2MB photo of Cookie in my Home folder. To compress it using Jpegoptim I would open a new Terminal session and run:

jpegoptim cookie.jpeg

After the command has ‘done its thang’ I can check the result. And, sure enough, the file is reduced from 1.2MB to …1.1MB.

Small change, right?

But that’s where we can get fancy and Jpegoptim can show off. The app also lets you  reduce a jpg to a specific size. 

There is an (obvious) tradeoff in setting an arbitrary file size limit: image quality. Specifying a file size will disable the lossless optimization (i.e., your image quality will take a nosedive) but it can dramatically reduce jpeg size.

How To Quickly Optimize Jpeg Images on Linux

To go back to our example, let us re-compress our photo of Cookie to something more web-friendly. Let’s reduce it from 1.1MB to a more manageable 100k (you can specify a file size in either kilobytes (k) or as a percentage (%):

jpegoptim --size=100k cookie.jpeg

Note that the argument stating the size comes before the image location and not after it.

The resulting image is roughly my chosen file-size (a rogue kb over) but has dropped in quality.

How To Quickly Optimize Jpeg Images on Linux

Other Features

It is also possible to optimise several images at once simply by listing them:

jpegoptim kittens.jpeg cats.jpg feline_good.jpg

Need to batch process an entire folder of jpegs? Jpegoptim can handle that too:

jpegoptim ~/Pictures/CatPhotos/*.jpeg

To see a full list of options and usage instructions for this utility run the following command:

man jpegoptim

Do you have a favourite command-line utility? Let us know about it in the comments below or by sending us a tip.

This article is part of our Linux Photography Toolbox series. Click here to see other entries.

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » How To Quickly Optimize Jpeg Images on Linux

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮