使用for迴圈產生網頁相簿

來源:互聯網
上載者:User

標籤:資源下載   根目錄   local   圖片   網頁   

將圖片資源下載到網站的根目錄(/usr/local/httpd/htdocs/)下。

1.下載並解壓縮:

yum -y install ImageMagick   ##安裝圖片轉換工具,支援convert

lftp ftp.linuxfan.cn

lftp ftp.linuxfan.cn:~> cd tools/                     

lftp ftp.linuxfan.cn:/tools> get for_html_img.tar.xz 

164757244 bytes transferred                             

lftp ftp.linuxfan.cn:/tools> bye


tar Jxvf for_html_img.tar.xz  ##解壓

cd img/


2.編寫指令碼:

[[email protected] img]# vim for_html.sh 

#!/bin/bash

##建立相簿

echo "Creating album..."

mkdir -p thumbs

###########建立html頭部###############

cat <<EOF >index.html

<html>

<head>

<style type="text/css">

body { 

width:960px; 

margin:0 auto; 

border:1px dashed grey; 

padding:10px; background:#000;

}

img { margin:5px; border:1px solid black;}

h1 { 

color:#fd6edf; 

font-size:48px; 

font-style:bold; 

font-family:"華文行楷"; width:400px; 

height:50px; 

background:#eded56;

}

</style>

</head>

<body>

<center><h1>www.linuxfan.cn</h1></center>

<embed src="ibl.mp3" autostart=true loop=true></embed>

<p>

EOF

###########為所有圖片設定a標籤###################

for img in *.jpg;

do

 convert "$img" -resize "300x" thumbs/$img    ##將大圖轉為小圖並放到thumbs/目錄下

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

done

###############建立網頁的尾部###############

cat <<END >>index.html

</p>

</body>

</html>

END

echo "index.html is ok."

:wq

[[email protected] img]# sh -x for_html.sh


3.訪問測試:

http://www.linuxfan.cn/img


本文出自 “12289734” 部落格,請務必保留此出處http://12299734.blog.51cto.com/12289734/1908241

使用for迴圈產生網頁相簿

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.