Last active
May 29, 2019 21:19
-
-
Save berdosi/03559c48dda2fe5e21f50d6154069950 to your computer and use it in GitHub Desktop.
generate a very basic overview of the pictures in a folder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# make a quick overview of the pictures in a folder | |
# I'm using this for Amazon S3, to have preview of the items I have in Deep Glacier | |
# create an empty folder: index/ | |
# make folder: index/thumbnails | |
# generate thumbnails for files | |
# generate index.html | |
# - generate metadata.js | |
# - add thumbnails | |
# - add metadata (todo) | |
# | |
rm -r index/ | |
mkdir -p ./index/thumbnails | |
RESIZETO=256x256 | |
STYLE=" | |
<style> | |
body { | |
font-family: sans-serif; | |
color: #999; | |
background-color: #222; | |
} | |
.container { | |
display: flex; | |
flex-wrap: wrap; | |
} | |
.thumbnail, .link { | |
display: block; | |
float: left; | |
box-sizing: border-box; | |
border: 1px solid #444; | |
width: 262px; | |
min-height: 262px; | |
padding: 2px; | |
} | |
.thumbnail img { | |
margin: auto; | |
display: block; | |
} | |
</style> | |
" | |
THUMBNAIL="<div class='thumbnail'><img src='thumbnails/__FILENAME__.jpg'><p>__FILENAME__</p></div>" | |
TITLE=`pwd | sed -e 's#.*/##'` | |
DOCHEADER="<!doctype html> | |
<head> | |
<meta charset='utf-8'> | |
<title>${TITLE}</title> | |
${STYLE} | |
</head> | |
<body> | |
<h1>${TITLE}</h1> | |
<p>Created on $(date) </p> | |
<hr> | |
<div class='container'> | |
" | |
DOCFOOTER="</div></body></html>" | |
echo $DOCHEADER > index/index.html | |
find *.jpg -print0 | xargs -0 -P 8 -I % convert -resize $RESIZETO '%' index/thumbnails/%.jpg | |
find *.jpeg -print0 | xargs -0 -P 8 -I % convert -resize $RESIZETO '%' index/thumbnails/%.jpg | |
find *.png -print0 | xargs -0 -P 8 -I % convert -resize $RESIZETO '%' index/thumbnails/%.jpg | |
find *.mp4 -print0 | xargs -0 -P 8 -I % ffmpeg -i % -deinterlace -an -ss 2 -f mjpeg -t 1 -r 1 -y -s 256x256 index/thumbnails/%.jpg | |
find -maxdepth 1 -type f -print0 | sort -z | xargs -0 -I % sh -c "echo \"$THUMBNAIL\" | sed -e s:__FILENAME__:%:g" >> index/index.html | |
echo $DOCFOOTER >> index/index.html | |
echo "Finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment