Skip to content

Instantly share code, notes, and snippets.

@mplscorwin
Created May 21, 2023 21:55
Show Gist options
  • Save mplscorwin/c0e8b2d37fba06e0832558d9e5463e1a to your computer and use it in GitHub Desktop.
Save mplscorwin/c0e8b2d37fba06e0832558d9e5463e1a to your computer and use it in GitHub Desktop.
#!/bin/bash
# create thumbs
rm .thumb/*-thumb.jpg # 2>/dev/null
(for f in *.jpg ; do
b=`basename "$f" .jpg`;
s=`identify "$f" | cut -d" " -f3 | perl -nle '
($width,$height) = split 'x';
die "bad size" unless $width && $height;
($max_w,$max_h) = (64,128);
$k_w = $max_w / $width;
$k_h = $max_h / $height;
# https://fastapi.metacpan.org/source/SHERZODR/Image-Resize-0.5/Resize.pm
$k = ($k_h < $k_w ? $k_h : $k_w);
$new_w = int($height * $k);
$new_h = int($width * $k);
print $new_w.'x'.$new_h
'`;
t=".thumb/$b-thumb.jpg" ;
convert -resize $s -quality 50 "$f" "$t" 1>&2
if [[ -f $t ]] ; then
printf 'AddDescription '"'"'<a href="%s"><img src="%s" data-size="%s"></a>'"'"' %s\n' \
"$f" "$t" "$s" "$f";
fi
done) | tee .htaccess
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment