Linux系统压缩目录下的图片
标签搜索
侧边栏壁纸
  • 累计撰写 2 篇文章
  • 累计收到 0 条评论

Linux系统压缩目录下的图片

admin
2024-11-24 / 0 评论 / 7 阅读 / 正在检测是否收录...
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#!/bin/bash

# 查找目录及子目录的图片文件(jpg,gif,png),将大于某值的图片进行压缩处理

# Config

folderPath='/www/wwwroot/salon/attachment/behram_pic'   # 图片目录路径

maxSize='100KB'    # 图片尺寸允许值
maxWidth=640   # 图片最大宽度
maxHeight=500  # 图片最大高度
quality=80      # 图片质量


# 压缩处理
# Param $folderPath 图片目录
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

            # 调用imagemagick resize图片
            $(convert -resize "$maxWidth"x"$maxHeight" "$file" -quality "$quality" -colorspace sRGB "$file")

        done

    else
        echo "$folderPath not exists"
    fi
}

# 执行compress
compress "$folderPath"

exit 0
echo "----------------------------------------------------------------------------"
endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"
0

评论 (0)

取消