How to use the command jpegoptim (with examples)

How to use the command jpegoptim (with examples)

JPEGoptim is a command-line tool that allows users to optimize JPEG images by reducing their file size while retaining the quality of the images. With JPEGoptim, users can strip unnecessary data from JPEG images, convert them to the progressive format, and even set a maximum file size for the optimized images.

Use case 1: Optimise a set of JPEG images, retaining all associated data

Code:

jpegoptim image1.jpeg image2.jpeg imageN.jpeg

Motivation: This use case is useful when you want to optimize the file size of a set of JPEG images without losing any important data associated with the images, such as EXIF metadata.

Explanation: In this use case, the command jpegoptim is followed by the filenames of the JPEG images you want to optimize. By running this command, JPEGoptim will optimize the images while retaining all associated data, including EXIF metadata.

Example output:

image1.jpeg 1280x800 24bit N JFIF  [OK] 204928 --> 196166 bytes (4.26%), optimized.
image2.jpeg 1920x1080 24bit N JFIF  [OK] 550048 --> 523946 bytes (4.77%), optimized.
imageN.jpeg 1280x720 24bit N JFIF  [OK] 321640 --> 310982 bytes (3.32%), optimized.

Use case 2: Optimise JPEG images, stripping all non-essential data

Code:

jpegoptim --strip-all image1.jpeg image2.jpeg imageN.jpeg

Motivation: This use case is useful when you want to reduce the file size of JPEG images significantly by removing all non-essential data, such as EXIF metadata, comments, and thumbnails.

Explanation: In this use case, the --strip-all argument is added to the command. This argument instructs JPEGoptim to remove all non-essential data from the JPEG images during the optimization process.

Example output:

image1.jpeg 1280x800 24bit N JFIF  [OK] 204928 --> 185827 bytes (9.34%), optimized.
image2.jpeg 1920x1080 24bit N JFIF  [OK] 550048 --> 480246 bytes (12.71%), optimized.
imageN.jpeg 1280x720 24bit N JFIF  [OK] 321640 --> 285738 bytes (11.15%), optimized.

Use case 3: Force the output images to be progressive

Code:

jpegoptim --all-progressive image1.jpeg image2.jpeg imageN.jpeg

Motivation: This use case is useful when you want to convert JPEG images into the progressive format, which improves the user experience by gradually rendering the image on the screen, providing a preview even before the entire image is loaded.

Explanation: By adding the --all-progressive argument to the command, JPEGoptim will force the output images to be in the progressive format. Progressive JPEGs load faster and allow viewers to see a low-quality version of the image while it progressively improves.

Example output:

image1.jpeg 1280x800 24bit N JFIF  [OK] 204928 --> 196166 bytes (4.26%), optimized.
image2.jpeg 1920x1080 24bit N JFIF  [OK] 550048 --> 523946 bytes (4.77%), optimized.
imageN.jpeg 1280x720 24bit N JFIF  [OK] 321640 --> 310982 bytes (3.32%), optimized.

Use case 4: Force the output images to have a fixed maximum filesize

Code:

jpegoptim --size=250k image1.jpeg image2.jpeg imageN.jpeg

Motivation: This use case is useful when you want to set a maximum file size for the optimized images. It is particularly helpful when you have limitations on the file size that you can upload or when you want to reduce the file size to a specific target size.

Explanation: By adding the --size=250k argument to the command, JPEGoptim will optimize the JPEG images and enforce a maximum file size of 250 kilobytes. The images will be compressed further until the file size reaches or is smaller than the specified limit.

Example output:

image1.jpeg 1280x800 24bit N JFIF  [OK] 204928 --> 103604 bytes (49.44%), optimized.
image2.jpeg 1920x1080 24bit N JFIF  [OK] 550048 --> 252943 bytes (54.05%), optimized.
imageN.jpeg 1280x720 24bit N JFIF  [OK] 321640 --> 207860 bytes (35.4%), optimized.

Conclusion

JPEGoptim is a powerful command-line tool that provides various options for optimizing JPEG images. Whether you want to retain all data, strip non-essential data, convert to the progressive format, or set a maximum file size, JPEGoptim can efficiently handle these use cases. By understanding and utilizing the different options, you can effectively optimize your JPEG images and reduce their file sizes while maintaining the desired image quality.

Related Posts

How to use the command 'ocamlc' (with examples)

How to use the command 'ocamlc' (with examples)

The ‘ocamlc’ command is the OCaml bytecode compiler. It is used to compile OCaml source files into executables that can be run by the OCaml interpreter.

Read More
Applying Dithering to a Greyscale Image with `pamditherbw` (with examples)

Applying Dithering to a Greyscale Image with `pamditherbw` (with examples)

Dithering is a technique used to convert a greyscale image into a pattern of black and white pixels that closely resemble the original image.

Read More
How to use the command 'checkinstall' (with examples)

How to use the command 'checkinstall' (with examples)

Checkinstall is a command-line tool used to track the local installation of a software package and produce a binary package that can be used with a system’s native package manager.

Read More