The user uploads the picture, generally has not been compressed, causes the space to waste. So you need to write a program that looks up a picture file (jpg,gif,png) of directories and subdirectories, and compresses pictures that are larger than a certain value.
The code is as follows:
#!/bin/bash
# Look up a picture file (jpg,gif,png) for a directory and subdirectories, compress a picture that is larger than a value in
# Config
folderpath= '/home/fdipzone/photo ' # Picture directory path
maxsize= ' 1M ' # picture size allowable value
maxwidth=1280 # picture max width
maxheight=1280 # picture Max height
QUALITY=85 # image quality
# compression processing
# Param $folderPath picture directory
function compress () {
folderpath=$1
If [-D "$folderPath"]; Then for
file in $ (find "$folderPath" (-name "*.jpg"-or-name "*.gif"-or-name "*.png")-type f-size + "$maxSize" ); Do
echo $file
# call ImageMagick resize picture
$ (convert-resize "$maxWidth" x "$maxHeight" "$file"-quality "$ Quality "$file")
performed else echo "$folderPath NOT exists"
fi
}
# Execute Compress
Compress "$folderPath"
exit 0
This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/