All about Linux kernel and operating systems that are based on it.
[Random post]

 tags  gallery  RSS

28.2.2023 21:49:42 reposted from juozaspo

Oneline random image html file generator

The command below generates a html file pointing to 100 random image files found in the directory tree of the working directory. You can adjust it to your needs by putting the paths you want to exclude or adding more extensions to placeholders as shown below. The output file shows images centered on screen, with max widths no larger than screen.

echo -e "<html>\n<head>\n<title>Random Images</title>\n</head>\n<style>\nimg {max-width:100%; height:auto}\nbody{text-align:center}\n</style>\n<body>\n$(find -type f -not \( -ipath "./paths/*" -or -ipath "./to/*" -or -ipath "./exclude/*" \) -and \( -iname "*.jpg" -or -iname "*.jpeg" -or -iname "*.png" -or -iname "*.gif" -or -iname "*.webp" -or -iname "*.bmp" \) | cut -d\/ -f2- | sort | shuf -n 100 | tr '\n' '\0' | xargs -0 -I{} echo "<div style=\"margin:auto\"><img title=\"{}\" src=\"$(realpath "{}")\"></div>")</body>\n<html>" > /tmp/random.htm

The output file is saved as /tmp/random.htm