Realignment the hotspots of Auto-cropped cursor
This article is just a translation of Auto-cropしたカーソルのhotspotを揃え直す.
A cursor which is saved by X11 Mouse Cursor plug-in for GIMP(gimp-xmc-plugin) with "Auto-crop" option has different hotspots coordinates for different frames. This is not a matter if you edit it by GIMP(+gimp-xmc-plugin) because gimp-xmc-plugin aligns the position of frames automatically, but if you edit it by other image manipulating program*1, it may be problem.
You need to follow these steps if you want to rearrange the hotspots of Auto-cropped cursor to set them on same coordinates.
- Open the cursor by GIMP(+gimp-xmc-plugin)
- Apply "Layer to Image size" for all layers
- Save it without "Auto-crop" option
It's boring to do this by hand and you may want to handle many cursors. Fortunately, GIMP has batch mode and can manipulate multiple images from console. I write a GIMP-Python script to do the operation mentioned above.
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 cropped", "tks", "2008/10/02", "", "RGBA", [(PF_STRING, "file_pattern", "File_Pattern", None)], [], restore_cropped) main()
To use this script, set executable permission to restore_cropped.py, move it in ~/.gimp-2.4/plug-ins, and type like this.
Then, all cursors named as "*.xmc" in directory "mydir" are rearranged by the way mentioned above.
$ []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[]
Reference
- GIMP Python Documentation
- GIMP - Batch Mode
- Gimp-Python batch how-to
- gimp-python plugin template by Mr. Greg MacDonald
*1:for example xcur2png→ImageMagick→xcursorgen