Update python-fu-removebg with using subproccess

os.system => subprocess
This commit is contained in:
Maniu
2024-11-09 15:55:37 +01:00
committed by GitHub
parent 26a8c92f4f
commit f324175e8d

View File

@@ -12,6 +12,7 @@ from gi.repository import Gio
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk from gi.repository import Gtk
import os, sys, string, tempfile, platform import os, sys, string, tempfile, platform
import subprocess
def N_(message): return message def N_(message): return message
def _(message): return GLib.dgettext(None, message) def _(message): return GLib.dgettext(None, message)
@@ -82,18 +83,23 @@ class PythonRemoveBG(Gimp.PlugIn):
AlphaMatting = config.get_property('AlphaMatting') AlphaMatting = config.get_property('AlphaMatting')
asMask = config.get_property('asMask') asMask = config.get_property('asMask')
selModel = config.get_choice_id("Model") selModel = config.get_choice_id("Model")
aeValue = config.get_property('aeValue')
removeTmpFile = True removeTmpFile = True
osName = platform.system()
exportSep = str(os.sep)
tdir = tempfile.gettempdir() tdir = tempfile.gettempdir()
print(tdir) print(tdir)
jpgFile = "%s%sTemp-gimp-0000.jpg" % (tdir, exportSep) jpgFileF = "Temp-gimp-0000.jpg"
pngFile = "%s%sTemp-gimp-0000.png" % (tdir, exportSep) jpgFile = os.path.join(tdir,jpgFileF)
pngFileF = "Temp-gimp-0000.png"
pngFile = os.path.join(tdir,pngFileF)
x1 = 0 x1 = 0
y1 = 0 y1 = 0
option = "" option = ""
Gimp.context_pop() Gimp.context_pop()
@@ -121,11 +127,13 @@ class PythonRemoveBG(Gimp.PlugIn):
pdb.gimp_image_delete(tmpImage) pdb.gimp_image_delete(tmpImage)
aiExe = "C:\\Program Files (x86)\\Rembg\\rembg.exe" aiExe = "C:\\Program Files (x86)\\Rembg\\rembg.exe"
if AlphaMatting: if AlphaMatting:
option = "-a -ae %d" % (aeValue) option = "-a -ae %d" % (aeValue)
cmd = '""%s" i -m %s %s "%s" "%s""' % (aiExe, tupleModel[selModel], option, f.get_path(), pngFile) cmd = '%s i -m %s %s "%s" "%s"' % (aiExe, tupleModel[selModel], option, f.get_path(), pngFile)
os.system(cmd) print(cmd)
subprocess.run(cmd)
file_exists = os.path.exists(pngFile) file_exists = os.path.exists(pngFile)
if file_exists: if file_exists: