Auto-cropしたカーソルのhotspotを揃え直す
X11 Mouse Cursor plug-in for GIMP(gimp-xmc-plugin)でAuto-cropを有効にして保存したカーソルは、各フレームのhotspotの座標が異なる場合がある。再度GIMP(+gimp-xmc-plugin)で開いて編集する場合はフレームの位置を自動で調整するので問題ないが、もし他の画像編集ソフトで開いて編集する場合*1は問題になるかもしれない。
既にAuto-cropしたカーソルのhotspotを同じ位置に揃え直すには、
という手順を踏むことになる。
これを手で行うのはかなり面倒だし、場合によっては大量のカーソルに適用したいかもしれない。幸いな事にGIMPにはバッチモードがあり、コンソールから複数の画像を一気に扱える。そこでこれを実行するスクリプトをGIMP-Pythonで書いてみた。
restore_cropped.py:
#!/usr/bin/env python # -*- coding: utf-8 -*- from gimpfu import * import glob #Remove comment out for interactive mode. def restore_cropped(file_pattern): file_list = glob.glob(file_pattern) file_list.sort() for file_name in file_list: image = pdb.file_xmc_load(file_name, file_name) display = gimp.Display(image) for layer in image.layers: layer.resize_to_image_size() #gimp.displays_flush() pdb.file_xmc_save(image, None, file_name, file_name, -1, -1, #retain hotspot coordinate 0, #do not auto-crop 0, 0, #do not change size 0, 0, #do not change delay None, None, None) #do not change comments gimp.delete(image) #gimp.delete(display) register( "xmc-restore-cropped", "arrange hotspots on same coordinates", "This plug-in arrange hotspots of all frames on same coordinates", "XMC restore crop", "tks", "2008/10/02", "", "RGBA", [(PF_STRING, "file_pattern", "File_Pattern", None)], [], restore_cropped) main()
実際に使用するにはrestore_cropped.pyに実行パーミッションを与えて「~/.gimp-2.4/plug-ins」に放り込み以下の様に打ち込む。
これで「mydir」ディレクトリのなかの「*.xmc」に一致するファイルに対し上記の操作が適用される。
$ []gimp -idfs --batch-interpreter python-fu-eval \[]
[] -b "pdb.python_fu_xmc_restore_cropped('mydir/*.xmc')" -b "pdb.gimp_quit(0)"[][]batch command executed successfully[]
[]plug-in 'python-eval.py' aborted before sending its procedure return values[]
参考サイト:
- GIMP Python Documentation
- GIMP - Batch Mode
- Gimp-Python batch how-to
- Greg MacDonald氏によるgimp-python plugin template
*1:例えばxcur2png→ImageMagick→xcursorgen