Shell bulk Compress pictures within specified folder and subfolders
The user uploads the picture, generally has not been compressed, causes the space to waste. Therefore, you need to write a program to find the folder and subfolders of the picture file (jpg,gif,png), the image is larger than a value compression processing.
The code is as follows:
#!/bin/bash# find picture files for folders and subfolders (jpg,gif,png), compress images larger than a value # configfolderpath= '/home/fdipzone/photo ' # Picture folder path maxsize= ' 1M ' # picture size agree value maxwidth=1280 # picture Max width maxheight=1280 # picture Max height quality=85 # picture quality # compression Processing # Param $folderPath Picture folder function compress () { folderpath=$1 if [-d ' $folderPath "]; then for file in $ (find" $f Olderpath "\ (-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 "-colorspace SRGB" $file ") done else Echo ' $folderPath not exists ' fi}# Run Compresscompress "$folderPath" Exit 0
Shell bulk Compress pictures within specified folder and subfolders