我回答我的問題。在Makefile
中,必須創建並使用臨時Gimp目錄,以便使用版本控制系統中的腳本,而不是任意的本地副本。一個人應該批處理圖像文件,因爲Gimp啓動相對較慢。
mkdir -p gimp/plug-ins
cp downsize.py gimp/plug-ins/
GIMP2_DIRECTORY=`pwd`/gimp gimp --no-interface \
--batch '(python-fu-downsize RUN-NONINTERACTIVE 600 32 "origdir" "copydir")' \
--batch '(gimp-quit 0)'
腳本downsize.py
是正常的瘸子Python腳本,它主要包含類似:
def downsize(img_w, img_d, in_dir, out_dir):
for fn in glob.glob(os.path.join(in_dir, "*.png")):
img = pdb.gimp_file_load(fn, '1')
if img.width > img_w:
aspect = float(img.width)/float(img.height)
h = int(float(img_w)/aspect)
pdb.gimp_image_scale(img, img_w, h)
if img.base_type != RGB:
pdb.gimp_convert_rgb(img)
if img.base_type != INDEXED:
pdb.gimp_convert_indexed(img, NO_DITHER, MAKE_PALETTE, img_d, False, True, "")
new_path = os.path.join(out_dir, os.path.basename(fn))
pdb.gimp_file_save(img, pdb.gimp_image_active_drawable(img), new_path, fn)
此代碼可能是不正確的,這僅僅是基本的想法。
感謝您的提示。不幸的是,pngcrush似乎錯過了索引顏色,所以與使用Gimp壓縮的圖像相比,由此產生的圖像仍然是雙倍的。 – Martin
你有沒有嘗試過:pngcrush -c 3 image.png? –
是的,但手冊頁說「如果輸入文件中存在256或更少的顏色,pngcrush的未來版本**也將允許顏色類型3」。我的1.7.9版本不是最新版本,但更新日誌沒有提及任何新功能。 – Martin