CutCodeDown

Web Development => Snippet Sharing => Topic started by: fgm on 26 Nov 2019, 11:04:47 am

Title: Shell script: thumbnail generator using ImageMagick
Post by: fgm on 26 Nov 2019, 11:04:47 am
This is the code I wrote some time ago to generate thumbnails for my static sites following Google recommendations. Full sized photos are 1200x800 and the miniatures are shown at 300x200, so I generate double sized thumbnails to be zoom-friendly as Jason recommends:
Code: [Select]
#!/bin/sh
cd /image/directory
for i in `find . -name "*jpg"`;
do
        echo $i;
        convert -resize 600x400 -sampling-factor 4:2:0 -strip -quality 80 -interlace JPEG -colorspace RGB $i -set filename:new '%t_thumb' %[filename:new].jpg;
done

This is the robots.txt entry to avoid getting the thumbnails indexed in Google:
Code: [Select]
User-agent: Googlebot-Image
Disallow: /images/*_thumb.jpg$