Skip to content

Instantly share code, notes, and snippets.

@bwhmather
Created January 9, 2014 23:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwhmather/8344366 to your computer and use it in GitHub Desktop.
Save bwhmather/8344366 to your computer and use it in GitHub Desktop.
simple script for converting from xcf to png using gimp
#!/usr/bin/env python
from subprocess import call
from sys import argv
from os.path import abspath
# encode + decode required for python 3
# TODO make sure that scheme escapes in the same way as c
infile = abspath(argv[1]).encode('unicode_escape').decode('utf-8')
outfile = abspath(argv[2]).encode('unicode_escape').decode('utf-8')
script = """
(define infile "{infile}")
(define outfile "{outfile}")
(define image (car (gimp-file-load RUN-NONINTERACTIVE infile infile)))
(define drawable (car (gimp-image-merge-visible-layers image CLIP-TO-IMAGE)))
(file-png-save-defaults RUN-NONINTERACTIVE image drawable outfile outfile)
(gimp-quit 0)
""".format(infile=infile, outfile=outfile)
call(['gimp', '--no-interface', '--no-data', '--no-fonts',
'--batch', script], shell=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment