· 9 years ago · Nov 16, 2016, 01:08 PM
1#!/bin/sh
2# Copyright (c) 2016, Alexandre Hamelin <alexandre.hamelin gmail.com>
3# Generate thumbnails from a directory.
4
5[[ $# -ge 2 ]] || {
6 echo "usage: $0 size images... (ex: 160 1.jpg 2.jpg)"
7 exit 1
8}
9
10[[ $(type -t convert) == file ]] || {
11 echo "requires ImageMagick to be installed"
12 exit 2
13}
14
15sz=$(($1))
16shift
17
18mkdir -p thumbnails
19for img in "$@"; do
20 img_lc=$(echo "$img" | tr A-Z a-z)
21 convert "$img" -auto-orient -resize ${sz}x${sz} "thumbnails/${img_lc/./_t.}"
22 printf .
23done
24echo
25
26cd thumbnails && cat >index.html <<EOF
27<!doctype html>
28<html>
29<head>
30 <title>Thumbnails of $(cd ..; echo ${PWD##*/})</title>
31 <style>
32 div { float: left; width: ${sz}px; height: ${sz}px; margin: 2px; display: inline-block; }
33 body { background: url($(ls|grep -v html|tail -n 1)) repeat-y;
34 background-size: 120% }
35 </style>
36</head>
37<body>
38$(ls | sed '/index.html/d; s|.*|<div style="background: url(&) no-repeat center"></div>|')
39</body>
40</html>
41EOF