Python Forum
attempting to run gimp-console from python in windows 10 - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: attempting to run gimp-console from python in windows 10 (/thread-13263.html)



attempting to run gimp-console from python in windows 10 - matteusbeus - Oct-07-2018

Hi all,
I'm trying to run gimp-console 2.8 via the subprocess.check_output command but it doesn't seem to work. I get "error [WinError 2] The system cannot find the file specified". If I use subprocess.Popen it's fine but obviously I don't want multiple console windows! Does anyone have an idea what I'm doing wrong?


RE: attempting to run gimp-console from python in windows 10 - buran - Oct-07-2018

Please post your code in code tags


RE: attempting to run gimp-console from python in windows 10 - matteusbeus - Oct-07-2018

import os, sys
from os import listdir
from os.path import isfile, join
import PIL
from PIL import Image
from PIL import ImageOps
import subprocess
import time
import argparse

def main():

    #size = 184, 138
    #size2 = 216, 120
    #	Usage: 	--size [filesize] --path [imgpath]
    #	Handle command line arguments for the script
    parser = argparse.ArgumentParser(description='Convert image files to file size and 15 colours for SGDK.')
    parser.add_argument('--size', help='Target size of images...')
    parser.add_argument('--path', help='Path of images convert...')

    if len(sys.argv)==1:
            parser.print_help()
            sys.exit(1)

    #	Parse arguments into namespace object to reference later in the script
    global args
    args = parser.parse_args()

    size = args.size
    print(size)
    path = args.path
    print(path)
  
    resizedOutputPath = path + "\\Resized\\"
    inputPath = path + "\\"
    outputPath = path + "\\Gimped\\"
    outputPath2 = outputPath.replace("\\", "\\\\")
    outputPath3 = outputPath.replace("\\", "\\\\")

    try:
        if not os.path.exists(resizedOutputPath):
            os.makedirs(resizedOutputPath)
    except IOError as e:
        print(e)

    try:
        if not os.path.exists(outputPath):
            os.makedirs(outputPath)
    except IOError as e:
        print(e)
             
    files = [f for f in listdir(path) if isfile(join(path, f))]
        
    for filename in files:
        print('Processing File: ' + filename)
        try:
            basewidth = 216
            img = Image.open(inputPath + filename)
            wpercent = (basewidth / float(img.size[0]))
            hsize = int((float(img.size[1]) * float(wpercent)))
            img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS)
            img = img.crop((0, 1, 216, 121))
            img.save(resizedOutputPath + filename)
            img.close()
            cmd = "gimp-console-2.8.exe -i -b \"(let* ( (image (car (file-png-load 0 \\" + "\"" + outputPath2 + filename + "\\\" \\\"" + outputPath2 + filename + "\\\")))(drawable (car (gimp-image-get-active-layer image))))(gimp-convert-rgb image) (gimp-image-convert-indexed image 0 0 16 0 1 \\\"\\\") (file-png-save 1 image drawable " + "\\\"" + outputPath3 + filename + "\\\" \\\"" + outputPath3 + filename + "\\\" 0 0 0 0 0 0 1) (gimp-quit 0))\""
            print(cmd)
            print(subprocess.check_output([cmd]))
        except IOError as e:
            print(e)
                 
if __name__ == "__main__":
    main()



RE: attempting to run gimp-console from python in windows 10 - matteusbeus - Oct-09-2018

Any help would be gratefully received