Webpagetest.org is a great tool to learn how you can improve your website loading time (you should use it if you aren’t using it already).
Today after running a report I’ve seen that we had a large image on the home page that can be compressed to minimize loading time.
Smaller images means faster pages, faster pages means happy users
. To compress images on Linux there are at least 2 alternatives:
OptiPNG: Advanced PNG Optimizer
OptiPNG is a PNG optimizer that recompresses image files to a smaller size, without losing any information. This program also converts external formats (BMP, GIF, PNM and TIFF) to optimized PNG, and performs PNG integrity checks and corrections.
Install optipng package from EPEL repository:
[root@silver ~]# yum install optipng [...] [root@silver ~]# optipng OptiPNG 0.6.2: Advanced PNG optimizer. Copyright (C) 2001-2008 Cosmin Truta. Type "optipng -h" for advanced help. Synopsis: optipng [options] files ... Files: Image files of type: PNG, BMP, GIF, PNM or TIFF Basic options: -h, -help show the advanced help -v verbose mode / show copyright, version and build info -o <level> optimization level (0-7) default 2 -i <type> interlace type (0-1) default <input> -k, -keep keep a backup of the modified files -q, -quiet quiet mode Examples: optipng file.png (default speed) optipng -o5 file.png (moderately slow) optipng -o7 file.png (very slow)
Pngcrush
Pngcrush is an optimizer for PNG (Portable Network Graphics) files. It can be run from a commandline in an MSDOS window, or from a UNIX or LINUX commandline.
Its main purpose is to reduce the size of the PNG IDAT datastream by trying various compression levels an PNG filter methods. It also can be used to remove unwanted ancillary chunks, or to add certain chunks including gAMA, tRNS, iCCP, and textual chunks.
Install pngcrush from DAG’s repository:
[root@silver ~]# yum install pngcrush [...] [root@silver ~]# pngcrush --help | pngcrush 1.7.3 | Copyright (C) 1998-2002,2006-2009 Glenn Randers-Pehrson | Copyright (C) 2005 Greg Roelofs | This is a free, open-source program. Permission is irrevocably | granted to everyone to use this version of pngcrush without | payment of any fee. | Executable name is pngcrush | It was built with libpng version 1.2.40, and is | running with libpng version 1.2.40 - September 10, 2009 | Copyright (C) 1998-2004,2006-2009 Glenn Randers-Pehrson, | Copyright (C) 1996, 1997 Andreas Dilger, | Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc., | and zlib version 1.2.3.3, Copyright (C) 1998-2002 (or later), | Jean-loup Gailly and Mark Adler. | It was compiled with gcc version 4.1.2 20080704 (Red Hat 4.1.2-46). [...] usage: pngcrush [options] infile.png outfile.png pngcrush -e ext [other options] files.png ... pngcrush -d dir [other options] files.png ... options: [...]
Now you can compress PNG images to reduce its size using command line:
[vitalie@silver ~]$ optipng -o7 example.png [vitalie@silver ~]$ pngcrush -brute -e ".compressed.png" *png
I’ve achieved 20% – 24% file size reduction after compression.
More on the subject:
Indopedia
Raymond.cc