在Linux系統上使用GIMP進行批量圖片處理可以通過多種方法實現,以下是一些常見的方法:
你可以編寫一個Shell腳本來自動化GIMP的一些重復任務。例如,創建一個腳本文件gimp_batch.sh
,內容如下:
#!/bin/bash
# 設置輸入和輸出文件夾
INPUT_FOLDER="/path/to/input/folder"
OUTPUT_FOLDER="/path/to/output/folder"
# 遍歷輸入文件夾中的所有圖片文件
for file in "$INPUT_FOLDER"/*.{jpg,png,bmp}
do
# 打開圖片
gimp "$file"
# 進行批量處理操作,例如調整大小、添加水印等
# 示例:調整所有圖片大小為800x600像素
gimp --batch-mode --resize=800,600 "$file"
# 保存處理后的圖片到輸出文件夾
mv "$file" "$OUTPUT_FOLDER"
done
然后給腳本執行權限:
chmod +x gimp_batch.sh
運行批處理腳本:
./gimp_batch.sh
GIMP的Python-Fu腳本提供了更強大的批量處理能力。以下是一個示例,展示如何使用Python-Fu腳本批量調整圖片大?。?/p>
import os
from PIL import Image
def batch_resize_images(input_directory, output_directory, size):
if not os.path.exists(output_directory):
os.makedirs(output_directory)
for filename in os.listdir(input_directory):
if filename.endswith(('.png', '.jpg', '.jpeg')):
file_path = os.path.join(input_directory, filename)
img = Image.open(file_path)
img_resized = img.resize(size, Image.ANTIALIAS)
output_filename = os.path.splitext(filename)[0] + "_resized." + os.path.splitext(filename)[1]
output_path = os.path.join(output_directory, output_filename)
img_resized.save(output_path)
print(f"Resized {file_path} to {output_path}")
# 定義輸入和輸出目錄
input_directory = "."
output_directory = "./resized_images"
size = (800, 600) # 指定目標大小
# 調用批量調整圖片大小的函數
batch_resize_images(input_directory, output_directory, size)
將上述腳本保存為batch_resize.py
,然后使用GIMP運行腳本:
gimp -i batch_resize.py
GIMP支持插件,你可以編寫或下載插件來擴展其功能。例如,使用BatchResize
插件可以幫助你批量調整圖像大小。
sudo apt-get install gimp-plugin-batchresize
濾鏡
-> 插件
BatchResize
圖像
-> 批處理
-> 批量調整大小
通過這些方法,你可以在Linux上使用GIMP進行批處理操作,提高工作效率。