linux shell 网页相册生成器

功能介绍:以下相册包含了许多本地图片,点击缩略图,就会出现一幅放大的图片。通过img标签存储图片,使用for循环对当前目录下的所有图片进行迭代。通过convert命令初始化图片大小。我们将所有的图片生成了一个HTML相册index.html。

如果系统没有convert命令:yum install ImageMagick -y

convert命令详解,请参考以下文章

https://www.cnblogs.com/beyang/p/7597819.html

 

效果如下:

 

 #! /bin/bash

 

echo "Creating album"

mkdir -p thumbs

cat <<EOF1 > index.html

<html>

<head>

<style>

body

{

        width:470px;

        margin:auto;

        border:1px dashed grey;

        padding:10px;

}

img

{

        margin:5px;

        border:1px solid black;

}

<style>

</head>

<body>

<center><h1>  #Album title</h1></center>

<p>

EOF1

 

for img in *.jpeg

do

        convert "$img" -resize "100x" "thumbs/$img"

        echo "<a href=\"$img\"><img src=\"thumbs/$img\" title=\"$img\"></a>" >> index.html

done

 

cat <<EOF2 >> index.html

</p>

</body>

</html>

EOF2

 

echo Album generated to index.html

posted @ 2021-07-12 09:18  香饼  阅读(152)  评论(0编辑  收藏  举报