# 5c8224a79d947

奧德賽

#!/bin/bash
# -------------------------------------------------------------------------------------------
# ImageMagick 重新產生圖片 ( 2018 / 12 / 25 )
# -------------------------------------------------------------------------------------------
# 變數設置區
# -------------------------------------------------------------------------------------------
# 設定來源目錄;不須加結尾的「/」
SourceDirectory=''
# 設定大圖目錄;不須加結尾的「/」
PictureDirectory=''
# 設定縮圖目錄;不須加結尾的「/」
ThumbnailDirectory=''
# 設定 ImageMagick 路徑
ImageMagickPath='/usr/local/ImageMagick/bin/magick'
# 設定 浮水印 路徑
WatermarkPath=''
# 設定 記錄檔 路徑
LogFile='ImageMagick.log'
# -------------------------------------------------------------------------------------------
# 腳本語法區
# -------------------------------------------------------------------------------------------
# 寫入開始執行時間(年-月-日 時:分:秒)
echo $(date +"%Y-%m-%d %H:%M:%S") >> $LogFile
# 取得來源目錄所有檔案名稱
for MonthDirectory in $(ls $SourceDirectory)
# 執行命令
do
	for FileName in $(ls $SourceDirectory/$MonthDirectory)
	do
		# 來源檔案路徑
		#echo $SourceDirectory/$MonthDirectory/$FileName >> $LogFile
		# 檢查大圖目錄
		if [ -d $PictureDirectory/$MonthDirectory ]; then
			echo "「 $PictureDirectory/$MonthDirectory 」目錄已存在!"
		else
			mkdir $PictureDirectory/$MonthDirectory
		fi
		# 大圖檔案路徑
		#echo $PictureDirectory/$MonthDirectory/$FileName >> $LogFile
		# 檢查縮圖目錄
		if [ -d $ThumbnailDirectory/$MonthDirectory ]; then
			echo "「 $ThumbnailDirectory/$MonthDirectory 」目錄已存在!"
		else
			mkdir $ThumbnailDirectory/$MonthDirectory
		fi
		# 縮圖檔案路徑
		#echo $ThumbnailDirectory/$MonthDirectory/$FileName >> $LogFile
		# 產生縮圖
		$ImageMagickPath convert -thumbnail 300x300 -gravity center -extent 300x300 $SourceDirectory/$MonthDirectory/$FileName $ThumbnailDirectory/$MonthDirectory/$FileName
		# 產生大圖
		$ImageMagickPath convert -resize 720x720^ $SourceDirectory/$MonthDirectory/$FileName $PictureDirectory/$MonthDirectory/$FileName
		echo 'OK!' >> $LogFile
	done
done
# 寫入結束執行時間(年-月-日 時:分:秒)
echo $(date +"%Y-%m-%d %H:%M:%S") >> $LogFile
echo '------------------------------------------------------------' >> $LogFile

更新:2018-12-20 11:31:44

人名
主題
訊息
 
 
驗證