首页
关于
Search
1
PHP图片判断大小压缩代码
8 阅读
2
Linux系统压缩目录下的图片
7 阅读
PHP
LINUX
登录
Search
标签搜索
压缩
Behram
累计撰写
2
篇文章
累计收到
0
条评论
首页
栏目
PHP
LINUX
页面
关于
搜索到
2
篇与
的结果
2024-11-24
Linux系统压缩目录下的图片
#!/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 "----------------------------------------------------------------------------"
2024年11月24日
7 阅读
0 评论
0 点赞
PHP图片判断大小压缩代码
2024年11月24日
8 阅读
0 评论
0 点赞
2024-11-24
//图片压缩开始了 if($fileInfo['type']=='image/jpeg' || $fileInfo['type']=='image/png' || $fileInfo['type']=='image/gif' || $fileInfo['type']=='image/jpg' || $fileInfo['type']=='image/webp') { if($fileInfo['type']=='image/png' || $fileInfo['type']=='image/gif'){ $this->ImageToJPG($img_path, $img_path, $imagewidth , $imageheight); } require_once VENDOR_PATH.'topthink/think_image.php'; $image = \think\Image::open($img_path); if($imagewidth < 720){ if($imagewidth > $imageheight){ $image->thumb($imagewidth, $imageheight)->save($img_path); //file_put_contents(ROOT_PATH.'/1.txt', print_r($imagewidth, true)); }else{ $image->thumb($imagewidth, $imagewidth, 3)->save($img_path); $imageheight = $imagewidth; } }else{ //file_put_contents(ROOT_PATH.'/kiqik.txt', print_r('kiqik', true)); if($imagewidth > $imageheight){ $zoom = $imagewidth / 720; $image->thumb(720, $imageheight/$zoom)->save($img_path); $imageheight = $imageheight/$zoom; $imagewidth = 720; }else{ $image->thumb(720, 720, 3)->save($img_path); $imagewidth = 720; $imageheight = 720; } } clearstatcache(); $fileInfo['size'] = filesize($img_path); } //图片压缩结束了