How to optimize images?

2

I was following some advice from PageSpeed Insights from Google and one of them is:

  

Formatting and properly compressing images can save many bytes of data.

In the meantime I've optimized them with a program - JpegMini - and even then there's still the suggestion to optimize the images (even after 30 seconds). Is there any other way to optimize them?

    
asked by anonymous 27.06.2017 / 21:13

2 answers

3

OptiPNG :

$ optipng /tmp/saturno.png
** Processing: /tmp/saturno.png
1041x1041 pixels, 8 bits/pixel, 195 colors in palette
Input IDAT size = 119947 bytes
Input file size = 120793 bytes

Trying:
  zc = 9  zm = 8  zs = 0  f = 0     IDAT size = 118148
  zc = 9  zm = 8  zs = 1  f = 5     IDAT size = 113455
  zc = 9  zm = 8  zs = 3  f = 5     IDAT size = 112036

Selecting parameters:
  zc = 9  zm = 8  zs = 3  f = 5     IDAT size = 112036

Output IDAT size = 112036 bytes (7911 bytes decrease)
Output file size = 112846 bytes (7947 bytes = 6.58% decrease)

jpegoptim :

$ jpegoptim /tmp/jupiter.jpg 
/tmp/jupiter.jpg 1920x1080 24bit N Exif IPTC XMP ICC Adobe  [OK] 175249 --> 174634 bytes (0.35%), optimized.

Sources: Image JPG and PNG

    
27.06.2017 / 21:36
1

Imagemin

An alternative would be imagemin , via the terminal using imagemin-cli or if you prefer via imagein-app application, but the latter does not work as well (by the trial version). There is also the possibility via Grunt or Gulp .

In case you use via terminal imagemin-cli :

# instalar o imagemin via npm
npm install -g imagemin-cli

# optimizar todas as imagens JPG/PNG/SVG de uma pasta
imagemin pasta_com_images/* -o pasta_de_destino/

Using the reference images (see below) for comparison it is verified that:

  • c-1920.jpg had a 6.7% reduction
  • pia01969-saturn-voyager1.png had a reduction of 11.8%

ImageOptim

Another alternative for bitmap images would be ImageOptim , via the terminal using Imageoptim-cli or if you prefer via imageoptim for MAC OS , or for other platforms . There is also the possibility via Grunt or Gulp .

In case you use via terminal imageoptim-cli :

# instalar via npm
npm install -g imageoptim-cli

# optimizar todas as imagens JPG/PNG de uma pasta
imageoptim -d ./pasta_com_images/

Using the reference images for comparison it is verified that:

  • c-1920.jpg had a reduction of 21.1%
  • pia01969-saturn-voyager1.png had a reduction of 10.7%

Summary

For this small experience, ImageOptim considerably reduced the JPEG image more than Imagenin (21.1% instead of 6.7%). The PNG image was close, obtaining the best image reduction (11.8% instead of the 10.7% of ImageOptim). On the other hand, imagemin also optimizes SVG images.

For the comparison, we used the source images JPG and PNG used in the Lacobus response .

For other examples see the following comparison

Hope you can help someone!

    
28.06.2017 / 01:55