From 06540bde9b88d11d723618a76c99acf918ef580d Mon Sep 17 00:00:00 2001 From: Marek Pistorius Date: Tue, 15 Apr 2025 14:24:15 +0200 Subject: [PATCH 01/12] Update python-fu-removebg.py Rename pchannel_choice to model_choice to more represent of purpose of that variable --- python-fu-removebg/python-fu-removebg.py | 36 ++++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/python-fu-removebg/python-fu-removebg.py b/python-fu-removebg/python-fu-removebg.py index 9d8c07a..173d83a 100644 --- a/python-fu-removebg/python-fu-removebg.py +++ b/python-fu-removebg/python-fu-removebg.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# (C) 2025 Marek Pistorius +# (C) 2024-2025 Marek Pistorius # This file is part of gimp-python-fu-removebg . # gimp-python-fu-removebg is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. # gimp-python-fu-removebg is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -50,25 +50,25 @@ class PythonRemoveBG(Gimp.PlugIn): procedure.add_double_argument("aeValue","aeValue","aeValue",0,100,15 ,GObject.ParamFlags.READWRITE) - pchannel_choice = Gimp.Choice.new() - pchannel_choice.add("u2net",0,"u2net","") - pchannel_choice.add("u2net_human_seg",1,"u2net_human_seg","") - pchannel_choice.add("u2net_cloth_seg",2,"u2net_cloth_seg","") - pchannel_choice.add("u2netp",3,"u2netp","") - pchannel_choice.add("silueta",4,"silueta","") - pchannel_choice.add("isnet-general-use",5,"isnet-general-use","") - pchannel_choice.add("isnet-anime",6,"isnet-anime","") - pchannel_choice.add("sam",7,"sam","") - pchannel_choice.add("birefnet-general",8,"birefnet-general","") - pchannel_choice.add("birefnet-cod",9,"birefnet-cod","") - pchannel_choice.add("birefnet-massive",10,"birefnet-massive","") - pchannel_choice.add("birefnet-portrait",11,"birefnet-portrait","") - pchannel_choice.add("birefnet-general-lite",12,"birefnet-general-lite","") - pchannel_choice.add("birefnet-hrsod",13,"birefnet-hrsod","") - pchannel_choice.add("birefnet-dis",14,"birefnet-dis","") + model_choice = Gimp.Choice.new() + model_choice.add("u2net",0,"u2net","") + model_choice.add("u2net_human_seg",1,"u2net_human_seg","") + model_choice.add("u2net_cloth_seg",2,"u2net_cloth_seg","") + model_choice.add("u2netp",3,"u2netp","") + model_choice.add("silueta",4,"silueta","") + model_choice.add("isnet-general-use",5,"isnet-general-use","") + model_choice.add("isnet-anime",6,"isnet-anime","") + model_choice.add("sam",7,"sam","") + model_choice.add("birefnet-general",8,"birefnet-general","") + model_choice.add("birefnet-cod",9,"birefnet-cod","") + model_choice.add("birefnet-massive",10,"birefnet-massive","") + model_choice.add("birefnet-portrait",11,"birefnet-portrait","") + model_choice.add("birefnet-general-lite",12,"birefnet-general-lite","") + model_choice.add("birefnet-hrsod",13,"birefnet-hrsod","") + model_choice.add("birefnet-dis",14,"birefnet-dis","") procedure.add_choice_argument ("Model", _("Model"), - _("Model"), pchannel_choice, + _("Model"), model__choice, "u2net", GObject.ParamFlags.READWRITE) return procedure From c837f83481650d61aa3925296318247b5019ffc5 Mon Sep 17 00:00:00 2001 From: Maniu Date: Sun, 25 May 2025 20:51:18 +0200 Subject: [PATCH 02/12] Update python-fu-removebg.py --- python-fu-removebg/python-fu-removebg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-fu-removebg/python-fu-removebg.py b/python-fu-removebg/python-fu-removebg.py index 173d83a..b73cd32 100644 --- a/python-fu-removebg/python-fu-removebg.py +++ b/python-fu-removebg/python-fu-removebg.py @@ -68,7 +68,7 @@ class PythonRemoveBG(Gimp.PlugIn): model_choice.add("birefnet-dis",14,"birefnet-dis","") procedure.add_choice_argument ("Model", _("Model"), - _("Model"), model__choice, + _("Model"), model_choice, "u2net", GObject.ParamFlags.READWRITE) return procedure From 06f66a3df1d835f356ed215bbcdc7139a45399e1 Mon Sep 17 00:00:00 2001 From: Maniu Date: Sun, 25 May 2025 21:14:16 +0200 Subject: [PATCH 03/12] Update python-fu-removebg.py --- python-fu-removebg/python-fu-removebg.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python-fu-removebg/python-fu-removebg.py b/python-fu-removebg/python-fu-removebg.py index b73cd32..a8d9a0b 100644 --- a/python-fu-removebg/python-fu-removebg.py +++ b/python-fu-removebg/python-fu-removebg.py @@ -16,6 +16,8 @@ from gi.repository import GLib from gi.repository import Gio gi.require_version('Gtk', '3.0') from gi.repository import Gtk +from pathlib import Path + import os, sys, string, tempfile, platform import subprocess @@ -131,7 +133,7 @@ class PythonRemoveBG(Gimp.PlugIn): pdb.file_jpeg_save(tmpImage, tmpDrawable, jpgFile, jpgFile, 0.95, 0, 1, 0, "", 0, 1, 0, 0) pdb.gimp_image_delete(tmpImage) - aiExe = "C:\\Program Files (x86)\\Rembg\\rembg.exe" + aiExe = Path("C:/Program Files (x86)/Rembg/rembg.exe") if AlphaMatting: option = "-a -ae %d" % (aeValue) From 0deee1f944d5a16e3631cf6c496ff7dc9bdf0a5f Mon Sep 17 00:00:00 2001 From: Maniu Date: Sun, 25 May 2025 21:15:08 +0200 Subject: [PATCH 04/12] Update python-fu-removebg.py --- python-fu-removebg/python-fu-removebg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-fu-removebg/python-fu-removebg.py b/python-fu-removebg/python-fu-removebg.py index a8d9a0b..e90b358 100644 --- a/python-fu-removebg/python-fu-removebg.py +++ b/python-fu-removebg/python-fu-removebg.py @@ -133,7 +133,7 @@ class PythonRemoveBG(Gimp.PlugIn): pdb.file_jpeg_save(tmpImage, tmpDrawable, jpgFile, jpgFile, 0.95, 0, 1, 0, "", 0, 1, 0, 0) pdb.gimp_image_delete(tmpImage) - aiExe = Path("C:/Program Files (x86)/Rembg/rembg.exe") + aiExe = Path("C://Program Files (x86)/Rembg/rembg.exe") if AlphaMatting: option = "-a -ae %d" % (aeValue) From ee660b34e6b4f67ea1a42a409ce5d35e769bb714 Mon Sep 17 00:00:00 2001 From: Maniu Date: Sun, 25 May 2025 21:29:08 +0200 Subject: [PATCH 05/12] Update python-fu-removebg.py --- python-fu-removebg/python-fu-removebg.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/python-fu-removebg/python-fu-removebg.py b/python-fu-removebg/python-fu-removebg.py index e90b358..3fdf424 100644 --- a/python-fu-removebg/python-fu-removebg.py +++ b/python-fu-removebg/python-fu-removebg.py @@ -147,10 +147,6 @@ class PythonRemoveBG(Gimp.PlugIn): newlayer = Gimp.file_load_layer(run_mode,image,fileOut) image.insert_layer(newlayer, None,-1) - file = Gio.File.new_for_path(pngFile) - newLayer = Gimp.file_load_layer(run_mode,image,fileOut) - image.insert_layer(newlayer, None,-1) - if asMask: image.select_item(Gimp.ChannelOps.REPLACE, newlayer) image.remove_layer(newlayer) From a30bba7907f893c76d3440e792667bc19691758c Mon Sep 17 00:00:00 2001 From: Maniu Date: Sun, 25 May 2025 21:50:49 +0200 Subject: [PATCH 06/12] Update python-fu-removebg.py fix mask part --- python-fu-removebg/python-fu-removebg.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python-fu-removebg/python-fu-removebg.py b/python-fu-removebg/python-fu-removebg.py index 3fdf424..73b73cd 100644 --- a/python-fu-removebg/python-fu-removebg.py +++ b/python-fu-removebg/python-fu-removebg.py @@ -149,12 +149,12 @@ class PythonRemoveBG(Gimp.PlugIn): if asMask: image.select_item(Gimp.ChannelOps.REPLACE, newlayer) + copyLayer = newlayer.copy() image.remove_layer(newlayer) - copyLayer = Gimp.layer_copy(curLayer) image.insert_layer(copyLayer,None, -1) - mask = copyLayer.create_mask(ADD_SELECTION_MASK) + mask = copyLayer.create_mask(Gimp.AddMaskType.SELECTION) copyLayer.add_mask(mask) - Gimp.selection_none(image) + image.get_selection().none(image) image.undo_group_end() Gimp.displays_flush() From 5a47832ad33068ab7f9332bdb5b7ae65aa95e706 Mon Sep 17 00:00:00 2001 From: Maniu Date: Wed, 28 May 2025 19:38:16 +0200 Subject: [PATCH 07/12] Update python-fu-removebg.py --- python-fu-removebg/python-fu-removebg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-fu-removebg/python-fu-removebg.py b/python-fu-removebg/python-fu-removebg.py index 73b73cd..7afdb34 100644 --- a/python-fu-removebg/python-fu-removebg.py +++ b/python-fu-removebg/python-fu-removebg.py @@ -41,7 +41,7 @@ class PythonRemoveBG(Gimp.PlugIn): procedure.set_documentation (_("Remove Background AI"), _("Remove Background AI"), name) - procedure.set_menu_label(_("RemoveBG..")) + procedure.set_menu_label(_("RemoveBG")) procedure.set_attribution("MP", "(c) GPL V3.0 or later", "2024-2025") From 9c5511058562ad6f4e6f0a6f99f64c883826b4d2 Mon Sep 17 00:00:00 2001 From: Maniu Date: Wed, 28 May 2025 20:35:12 +0200 Subject: [PATCH 08/12] Update python-fu-removebg.py find path for rembg --- python-fu-removebg/python-fu-removebg.py | 37 ++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/python-fu-removebg/python-fu-removebg.py b/python-fu-removebg/python-fu-removebg.py index 7afdb34..66cad3d 100644 --- a/python-fu-removebg/python-fu-removebg.py +++ b/python-fu-removebg/python-fu-removebg.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# (C) 2024-2025 Marek Pistorius +# (C) 2024-2026 Marek Pistorius # This file is part of gimp-python-fu-removebg . # gimp-python-fu-removebg is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. # gimp-python-fu-removebg is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -17,7 +17,7 @@ from gi.repository import Gio gi.require_version('Gtk', '3.0') from gi.repository import Gtk from pathlib import Path - +from typing import Any, Callable, List, Optional, Tuple, Union import os, sys, string, tempfile, platform import subprocess @@ -25,6 +25,35 @@ def N_(message): return message def _(message): return GLib.dgettext(None, message) tupleModel = ("u2net","u2net_human_seg", "u2net_cloth_seg", "u2netp", "silueta", "isnet-general-use", "isnet-anime", "sam", "birefnet-general" ,"birefnet-general-lite", "birefnet-portrait", "birefnet-dis", "birefnet-hrsod", "birefnet-cod", "birefnet-massive" ) +REMBG_BASE_PATH = "" + +def find_rembg_install() -> Optional[Path]: + + home = sys.exec_prefix + + possible_paths = [] + # Common installation paths + if sys.platform == "win32": + possible_paths = [ + Path("C:/Program Files (x86)/RemBG/"), + Path("C:/Program Files/RemBG/"), + ] + + for path in possible_paths: + if path.is_dir(): + return path + + # Fallback to user-configured path if specified + if REMBG_BASE_PATH and (nik_path := Path(REMBG_BASE_PATH)).is_dir(): + return nik_path + + show_alert( + text="rembg installation path not found", + message="Please specify the correct installation path 'REMBG_BASE_PATH' in the script.", + ) + + return None + class PythonRemoveBG(Gimp.PlugIn): ## GimpPlugIn virtual methods ## def do_set_i18n(self, procname): @@ -133,7 +162,9 @@ class PythonRemoveBG(Gimp.PlugIn): pdb.file_jpeg_save(tmpImage, tmpDrawable, jpgFile, jpgFile, 0.95, 0, 1, 0, "", 0, 1, 0, 0) pdb.gimp_image_delete(tmpImage) - aiExe = Path("C://Program Files (x86)/Rembg/rembg.exe") +# aiExe = Path("C://Program Files (x86)/Rembg/rembg.exe") + aiExe = str(find_rembg_install()) + aiExe += "/rembg.exe" if AlphaMatting: option = "-a -ae %d" % (aeValue) From a26a28293e955d163ebfe4a5cfd28b9cdfa0661e Mon Sep 17 00:00:00 2001 From: Maniu Date: Wed, 28 May 2025 21:08:46 +0200 Subject: [PATCH 09/12] Update python-fu-removebg.py --- python-fu-removebg/python-fu-removebg.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python-fu-removebg/python-fu-removebg.py b/python-fu-removebg/python-fu-removebg.py index 66cad3d..44b37f0 100644 --- a/python-fu-removebg/python-fu-removebg.py +++ b/python-fu-removebg/python-fu-removebg.py @@ -35,8 +35,8 @@ def find_rembg_install() -> Optional[Path]: # Common installation paths if sys.platform == "win32": possible_paths = [ - Path("C:/Program Files (x86)/RemBG/"), - Path("C:/Program Files/RemBG/"), + Path("C:/Program Files (x86)/Rembg/"), + Path("C:/Program Files/Rembg/"), ] for path in possible_paths: From 8060eb115bc7c0d4cc02a15913a710819ee4b3e0 Mon Sep 17 00:00:00 2001 From: Maniu Date: Tue, 3 Jun 2025 13:17:01 +0200 Subject: [PATCH 10/12] Update python-fu-removebg.py add show_alert --- python-fu-removebg/python-fu-removebg.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/python-fu-removebg/python-fu-removebg.py b/python-fu-removebg/python-fu-removebg.py index 44b37f0..9e1bfb0 100644 --- a/python-fu-removebg/python-fu-removebg.py +++ b/python-fu-removebg/python-fu-removebg.py @@ -54,6 +54,23 @@ def find_rembg_install() -> Optional[Path]: return None +def show_alert(text: str, message: str, parent=None) -> None: + """Popup a message dialog with the given text and message""" + + dialog = Gtk.MessageDialog( + transient_for=parent, + flags=0, + message_type=Gtk.MessageType.ERROR, + buttons=Gtk.ButtonsType.CLOSE, + text=text, + ) + dialog.format_secondary_text(message) + dialog.set_title(f"{PROC_NAME} v{VERSION}") + dialog.run() + dialog.destroy() + + + class PythonRemoveBG(Gimp.PlugIn): ## GimpPlugIn virtual methods ## def do_set_i18n(self, procname): From 6a29c7d05cf9d30ec167dcc720ca0496cd38741b Mon Sep 17 00:00:00 2001 From: Maniu Date: Tue, 3 Jun 2025 13:26:21 +0200 Subject: [PATCH 11/12] Update python-fu-removebg.py --- python-fu-removebg/python-fu-removebg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-fu-removebg/python-fu-removebg.py b/python-fu-removebg/python-fu-removebg.py index 9e1bfb0..3875296 100644 --- a/python-fu-removebg/python-fu-removebg.py +++ b/python-fu-removebg/python-fu-removebg.py @@ -65,7 +65,7 @@ def show_alert(text: str, message: str, parent=None) -> None: text=text, ) dialog.format_secondary_text(message) - dialog.set_title(f"{PROC_NAME} v{VERSION}") + dialog.set_title(f"REMBG") dialog.run() dialog.destroy() From 44a0847efadfcbc26f9e7bfd8d2a42906abd4ff0 Mon Sep 17 00:00:00 2001 From: maniu Date: Sun, 22 Jun 2025 16:21:18 +0200 Subject: [PATCH 12/12] Update python-fu-removebg/python-fu-removebg.py Signed-off-by: maniu --- python-fu-removebg/python-fu-removebg.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python-fu-removebg/python-fu-removebg.py b/python-fu-removebg/python-fu-removebg.py index 3875296..325a8f2 100644 --- a/python-fu-removebg/python-fu-removebg.py +++ b/python-fu-removebg/python-fu-removebg.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# (C) 2024-2026 Marek Pistorius +# (C) 2024-2026 --- # This file is part of gimp-python-fu-removebg . # gimp-python-fu-removebg is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. # gimp-python-fu-removebg is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -88,7 +88,7 @@ class PythonRemoveBG(Gimp.PlugIn): _("Remove Background AI"), name) procedure.set_menu_label(_("RemoveBG")) - procedure.set_attribution("MP", + procedure.set_attribution("M", "(c) GPL V3.0 or later", "2024-2025") procedure.add_menu_path('/Filters/RemoveBG/')