JPEG format of files are usually seen in Photography devices. Abbreviation of “JPEG” is Joint Photographic Experts Group.The JPEG compression algorithm is at its best on photographs and paintings of realistic scenes with smooth variations of tone and color.
While optimizing website page load speed, I found JPEG files in the website was another reason. The file sizes were bigger in size due to picture loading time was increasing and hence webpage slow loading too.
In my last tutorial, I also wrote about optimizing PNG file.It will also helps in speeding up the web page loading, in case you have lots of png pics in website.
In linux world, there is wonderful tool available known as Jpegoptim. Which helps in optimizing/compressing the JPEG file without compromising its quality.
jpegoptim is used to optimize/compress jpeg files. Program supports lossless optimization,which is based on optimizing the Huffman tables. And so called “lossy” optimization where in addition to optimizing Huffman tables user can specify upperlimit for image quality. (Description Reference : man jpegoptim)
Install jpegoptim on Debian based operating system
To install on Debian and Ubuntu. Use below given command
sudo apt-get install jpegoptim
Install jpegoptim on Red Hat Based Operating System
To install jpegoptim on CentOS/RHEL/Scientific Linux , first install EPEL repo.(How to install EPEL as per O.S and its architecture)
In CentOS/RHEL/Scientific Linux, install the related EPEL version. The below practical is done in CentOS 6.5 (Arch: x86_64)
rpm -ivh http://dl.fedoraproject.org/pub/epel/6Server/x86_64/epel-release-6-8.noarch.rpm
Now use yum command to install jpegoptim
yum install jpegoptim
How to use jpegoptim
After installing the package “jpegoptim”, you will get the command in your linux system with same name that is jpegoptim
.
To optimize/compress the JPEG format file. Use the command syntax
jpegoptim FileName.JPEG
OR
jpegoptim [Options] FileName.JPEG
EXAMPLE:
In below given example, I am compressing the file called DSC02712.JPG.
Before using jpegoptim
command, the file size was 5.3 M (I used du
command to get file size)
After using jpegoptim
command, the file size was 4.2M (I used du
command to get file size)
Most important thing is after this, the quality of picture is not compromised.
See the below given reference from my laptop.
linux@tuxworld:~/Desktop/pics/zoo$ du -sh DSC02712.JPG 5.3M DSC02712.JPG linux@tuxworld:~/Desktop/pics/zoo$ linux@tuxworld:~/Desktop/pics/zoo$ jpegoptim DSC02712.JPG DSC02712.JPG 4896x2752 24bit Exif [OK] 5448610 --> 4326287 bytes (20.60%), optimized. linux@tuxworld:~/Desktop/pics/zoo$ linux@tuxworld:~/Desktop/pics/zoo$ du -sh DSC02712.JPG 4.2M DSC02712.JPG linux@tuxworld:~/Desktop/pics/zoo$
To know the options with jpegoptim tool, you can use two commands
man jpegoptim
OR
jpegoptim --help
Below are options available.
linux@tuxworld:~/Desktop$ jpegoptim --help jpegoptim v1.2.3 Copyright (c) Timo Kokkonen, 1996-2009. Usage: jpegoptim [options]-d , --dest= specify alternative destination directory for optimized files (default is to overwrite originals) -f, --force force optimization -h, --help display this help and exit -m[0..100], --max=[0..100] set maximum image quality factor (disables lossless optimization mode, which is by default on) -n, --noaction don't really optimize files, just print results -o, --overwrite overwrite target file even if it exists -p, --preserve preserve file timestamps -q, --quiet quiet mode -t, --totals print totals after processing all files -v, --verbose enable verbose mode (positively chatty) -V, --version print program version --strip-all strip all (Comment & Exif) markers from output file --strip-com strip Comment markers from output file --strip-exif strip Exif markers from output file --strip-iptc strip IPTC markers from output file --strip-icc strip ICC profile markers from output file linux@tuxworld:~/Desktop$
Note: You can also install the Jpegoptim from its source tar ball. You can download it from its project link.
Project Link : http://www.kokkonen.net/tjko/projects.html#Jpegoptim