使用Debian系統上的CXImage進行批量處理圖像,可以參考以下步驟:
tar -zxvf cximage-x.x.x.tar.gz
cd cximage-x.x.x
./configure
make
sudo make install
其中,x.x.x
是CXImage的版本號,請根據實際情況替換。batch_compress.sh
的腳本文件,并添加以下內容:#!/bin/bash
# 設置壓縮率,默認是60
COMPRESSION_RATE=60
# 要壓縮的圖片文件夾路徑
INPUT_FOLDER="/path/to/your/image/folder"
# 遍歷目標文件夾,遞歸到所有子文件夾
for root, dirs, files in $(find $INPUT_FOLDER -type d); do
for file in $root/*.{jpg,jpeg,png,gif}; do
# 獲取文件名
filename=$(basename "$file")
# 設置輸出文件路徑
output_file="$root/${filename%.jpg}_compressed.${file##*.}"
# 使用CxImage進行壓縮
cximage -q -o $output_file -q -c -r $COMPRESSION_RATE "$file"
done
done
請確保將/path/to/your/image/folder
替換為實際的圖片文件夾路徑。chmod +x batch_compress.sh
./batch_compress.sh
這個腳本會自動遍歷指定文件夾及其子文件夾中的所有圖像文件,并使用CXImage進行壓縮。你可以根據需要修改腳本中的壓縮率和文件格式。
請注意,CXImage的具體使用方法和API可能會隨著版本的更新而有所變化,建議查閱最新的官方文檔或示例代碼以獲取詳細信息。