Re: [Gimp-developer] Gimp choking on python invocation
- From: Vio <zazavio gmail com>
- To: gimp-developer-list gnome org
- Subject: Re: [Gimp-developer] Gimp choking on python invocation
- Date: Wed, 21 Nov 2012 14:21:56 -0500
Hey guys,
Small follow-up to close my issue.
First thanks to everyone for your kind help.
Second, while I haven't solved it the way I want it,
I went for the fast and easy path: talk to the gimp-server in scheme
Here's my little contribution to this discussion, code-wise.
It's a compacted client (30-something lines of code)
modified from elsewhere, adapted to my needs.
Also because I like small ... small is beautiful ;)
It does not mingle with gimp directly because I could not solve that issue
So talking to the gimp from afar: sockets
-- my_gimp_client.py ----------------------------
import struct, socket, os, time
def strtogimp(s): return 'G'+struct.pack("!h", len(s))+s
def do(cmd):
gs.send(strtogimp(cmd))
data=""
while len(data) < 4: data = data + gs.recv(1024)
mlen = struct.unpack("!h",data[2:4])[0]
while len(data) < mlen+4: data = data + gs.recv(1024)
file('/tmp/t/DATA_received_gimp','a').write('%s/n/n' % data)
if data[1]=='\001': raise RuntimeError(data[4:])
else: return data[4:]
# STARTUP
print"""gimp --no-interface -b '(plug-in-script-fu-server 1 10008
"/tmp/t/gimp.log")'&"""
os.system(
"""gimp --no-interface -b '(plug-in-script-fu-server 1 10008
"/tmp/t/gimp.log")'&""")
print 'sleep 12... gimp waking up ...'
time.sleep(12) #gimp wakes up: 10sec isn't enough, but 12sec is (on my box)
gs = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
gs.connect(('localhost', 10008))
print 'connection:',gs.getpeername() #just making sure we are in business
# WORK
print 'work...'
work3 = """
(define inpath "/tmp/t/rihanna.jpg")
(define outpath "/tmp/t/%d.jpg")
(define img (car (gimp-file-load RUN-NONINTERACTIVE inpath inpath)))
(gimp-image-get-name img)
(gimp-image-flatten img)
(define drawable (car (gimp-image-get-active-drawable img)))
(gimp-file-save RUN-NONINTERACTIVE img drawable outpath outpath)
""" # sorry for my Scheme code, just learned this thing since
yesterday ... and it shows ha...
gs.send(strtogimp(work3 % int(time.time()))) #customizing the scheme
script the silly way
print 'work ... sleep 2...'
time.sleep(2) # wait for the gimp to do its magic
# EXIT
print 'exit...'
gs.send(strtogimp('(gimp-quit 0)'))
gs.close()
os.system('ls /tmp/t') #checking out the result
-- /my_gimp_client.py ----------------------------
this code works on my box, hope you might find it useful.
obviously don't use it in production, but could be a nice starting
point for experimenting...
Keep the excellent Gimp work going guys!!
cheers!
vio
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]