mozilla / firefox-hardware-report

The Firefox Hardware Report was the precursor to the Firefox Public Data Report, to which it now redirects
https://data.firefox.com/dashboard/hardware
27 stars 13 forks source link

Resize headshots to 140x140 and optimize/minimize #99

Closed pdehaan closed 6 years ago

pdehaan commented 6 years ago

This should reduce the images/headshots/*.jpg directory from ~1.3M down to ~44K.

$ ls -lash images/headshots
 4.1K Apr 16 09:51 alessio.jpg
 4.1K Apr 16 09:51 almossawi.jpg
 5.8K Apr 16 09:51 avrignaud.jpg
 5.8K Apr 16 09:51 fbertsch.jpg
 3.4K Apr 16 09:51 jkarahalis.jpg
 4.3K Apr 16 09:51 rweiss.jpg

$ ls -lash images/headshots.old
 36K Apr 16 09:44 alessio.jpg
491K Apr 16 09:44 almossawi.jpg
133K Apr 16 09:44 avrignaud.jpg
197K Apr 16 09:44 fbertsch.jpg
454K Apr 16 09:44 jkarahalis.jpg
 56K Apr 16 09:44 rweiss.jpg

$ du -sh images/headshots # 44K
$ du -sh images/headshots.old # 1.3M
FILE NEW OLD
alessio.jpg 4.1K 36K
almossawi.jpg 4.1K 491K
avrignaud.jpg 5.8K 133K
fbertsch.jpg 5.8K 197K
jkarahalis.jpg 3.4K 454K
rweiss.jpg 4.3K 56K
TOTAL: 44K 1.3M
pdehaan commented 6 years ago

For anybody curious (and my own future reference), I used the sharp module to do some quick image resizing and minification:

const glob = require('glob');
const sharp = require('sharp');

const headshots = glob.sync('./images/headshots/*.jpg')
  .map(img => resizeImage(img, 140));

Promise.all(headshots)
  .then(() => console.log(`${headshots.length} images resized`))
  .catch((err) => console.error(err));

function resizeImage(src, width, height=width) {
  return sharp(src)
    .resize(width, height)
    .toFile(src + '.jpeg');
}

But seemingly you can't set the output filename to the same as the input filename, so I had to append some lame ".jpeg" file extension and then manually rename the 6 files in Finder.

openjck commented 6 years ago

This is great. Thank you!

openjck commented 6 years ago

1.3M down to 44K. Talk about a big improvement.