Hello @Ramel,
Welcome aboard in this community!
PIL (Pillow / Python Imaging Library) being for Python mostly, you may use the new gmic-py G’MIC Python binding. It has helpers for GmicImage to PIL.Image bidirectional conversions, as well as for scikit Image and numpy Image.
The details for this are on the gmic-py documentation website: gmic-py.readthedocs.io, especially the PIL support page. Also, the flipbook-making tutorial has some PIL<->G’MIC magic at the beginning.
import gmic
import numpy
from PIL import Image, ImageSequence
im = Image.open("moonphases.gif")
images_list = []
for frame in ImageSequence.Iterator(im):
images_list.append(gmic.GmicImage.from_PIL(frame))
gmic.run("display", images_list)
Right now, gmic-py
is available:
- for Linux through
pip install gmic
(see available versions here: gmic · PyPI ; you may get the latest unstable version through pip install gmic==2.9.4a1
)
- for MacOS through MacPorts (
port install gmic
), this is very new so, not documented yet on the gmic-py documentation website
- for Windows… not yet despite many requests… but you can use the Windows Subsystem Linux (WSL or WSL2) shell, and
pip install gmic
just the way you would for Linux, with possible display windows if you use vcxsrv. This is also quite new but undocumented yet.
gmic-py wraps the libgmic C++ library, so its gmic.run()
entry points imitates its C++ counterpart’s method signature which is gmic::run(commands, gmic_list of gmic_image buffers, gmic_list of gmic_image strings)
In gmic-py, your piece of code would need to be written as:
- first version, if you just care about saving to a filesystem file… without PIL:
import gmic
gmic.run("your command output yourfile.png") # note that the "display" command instead of output is your friend in gmic-py for popping up a preview window without your needing to save anything to a file
- second version, if you want to keep the resulting image(s) buffer(s) around and pass them on to numpy/PIL/scikit-image. Note that you must have numpy installed (pip install numpy) if you want PIL/gmic-py I/O, because the gmic-py’s PIL uses a GmicImage->numpy.ndarray->PIL.Image bridging (and backwards too) as there is a missing codec in PIL (interleaved float64…):
import gmic
import PIL
images = [] # the libgmic gmic_list of images is a pure Python list in gmic-py, you need to create one and tie to a variable first if you want to explore and handle your list later on for other operations
gmic.run('my_image.png -fx_solidify_td 75,1,20,0,0', images)
print(images) # shows a regular Python list of one GmicImage only I believe, depending on how fx_solidify_td alters your gmic images list
myPILImage = images[0].to_PIL() # your PIL Image object
If you intend to use gmic.run()
a lot, it is inefficient in terms of performance because it spawns and deletes a G’MIC interpeter object each time, instead of keeping one alive, tying a gmic.Gmic() object to a variable is the way to go. This is explained in tutorial 2.