Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I have rembg installed locally on 22.04 and it is working fine through Terminal.

It would be nice to know how to use the GIMP plugin though. Any help will be great.

PS: I am using the GIMP AppImage.  


I added the file from GIMP Chat to the plugins folder for the AppImage, but I do not see any PythonFu entry in the menu

I think the script is for Flatpak and I am using AppImage

There is a line in the script which says

cmd = "flatpak-spawn --host %s i %s %s %s" % (aiExe, option, jpgFile, pngFile)

Not sure which is the right command for the AppImage

There is also a part which says remove temporary files

if removeTmpFile:
        if osName == "Windows":
            del_command = "del \"%s%sTemp-gimp-0000.*\"" % (tdir, exportSep)
            del_command = "rm %s%sTemp-gimp-0000.*" % (tdir, exportSep)

Is the right command for Ubuntu?

I replaced the Chinese text with English. Not sharing because I have no intention to remove parts of original code distribute.

Looks like I have to install Python2 to get gimpfu working. Because there is a line saying

from gimpfu import *

Tried installing Python 2 and it says

python2 is already the newest version (2.7.18-3).

Not sure how to get the PythonFu working inside GIMP AppImage. Maybe Flatpak version is the only option.
I think the command to run the AppImage is simply


maybe the path before it
I do not have rmbg installed, a bit large / bloat for me and I try and keep a tight installation however;

Quote:...snip...I added the file from GIMP Chat to the plugins folder for the AppImage, but I do not see any PythonFu entry in the menu...

That depends on the appimage, old versions (2.10.22 / 25) from have a self contained python 2.7

New version from (Gimp 2.10.32) as with regular ubuntu release does not support python.

For running the appimage, instead of the more usual 'direct portable command' have you considered unpacking to a folder
./ --appimage-extract

..and running as a command something like this: /home/rich/Portable/gimp/squashfs-root/AppRun That is mine to start Gimp
Thanks admin

The AppImage is 2.10.25


I am not able to see the PythonFu entry at all.

I thought of replacing the " cmd = " right hand side in the plugin file using " ./AppImage ". Would be nice to know how to modify the lines to extract and then run. I am just a beginner with Python. Thanks.
Thanks for the tips. I did as you said. But when I use the option under PythonFu, it works but nothing happens to the image

cmd = "/home/demo/Downloads/squashfs-root/AppRun --host %s i %s %s %s" % (aiExe, option, jpgFile, pngFile)

This is what I have in the line for cmd instead of the command for Flatpak.

This is what I have now

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# James Huang <>

from gimpfu import *
import os, sys, string, tempfile
import platform

def python_fu_RemoveBG(image, drawable, asMask, AlphaMatting, aeValue):
    removeTmpFile = True
    osName = platform.system()
    exportSep = str(os.sep)
    tdir = tempfile.gettempdir()
    #tdir = "./"
    jpgFile = "%s%sTemp-gimp-0000.jpg" % (tdir, exportSep)
    pngFile = "%s%sTemp-gimp-0000.png" % (tdir, exportSep)
    x1 = 0
    y1 = 0
    option = ""

    curLayer = pdb.gimp_image_get_active_layer(image)

    if pdb.gimp_selection_is_empty(image):
        pdb.file_jpeg_save(image, drawable, jpgFile, jpgFile, 0.95, 0, 1, 0, "", 0, 1, 0, 0)
        non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image)
        tmpImage = gimp.Image(x2-x1, y2-y1, 0)
        tmpDrawable = gimp.Layer(tmpImage, "Temp", tmpImage.width, tmpImage.height, RGB_IMAGE, 100, NORMAL_MODE)
        pdb.gimp_image_add_layer(tmpImage, tmpDrawable, 0)
        pat = pdb.gimp_context_get_pattern()
        pdb.gimp_drawable_fill(tmpDrawable, 4)
        pdb.file_jpeg_save(tmpImage, tmpDrawable, jpgFile, jpgFile, 0.95, 0, 1, 0, "", 0, 1, 0, 0)
    aiExe = "/home/demo/.local/bin/rembg"
    if AlphaMatting:
        option = "-a -ae %d" % (aeValue)
    cmd = "flatpak-spawn --host %s i %s %s %s" % (aiExe, option, jpgFile, pngFile)

    file_exists = os.path.exists(pngFile)
    if file_exists:
        newlayer = pdb.gimp_file_load_layer(image, pngFile)
           image.add_layer(newlayer, -1)
           pdb.gimp_layer_set_offsets(newlayer, x1, y1)
           if asMask:
               pdb.gimp_image_select_item(image, CHANNEL_OP_REPLACE, newlayer)
            copyLayer = pdb.gimp_layer_copy(curLayer, TRUE)
            image.add_layer(copyLayer, -1)


    if removeTmpFile:
        if osName == "Windows":
            del_command = "del \"%s%sTemp-gimp-0000.*\"" % (tdir, exportSep)
            del_command = "rm %s%sTemp-gimp-0000.*" % (tdir, exportSep)

    "AI Remove, AI Remove image background",
    "AI Remove, AI Remove image background",
    "JamesH, <>",
    "<Image>/Python-Fu/AI Remove(AI Remove background) ...",
       (PF_TOGGLE, "asMask", ("As Mask (as Mask)"), True),
       (PF_TOGGLE, "AlphaMatting", ("alpha matting"), False),
       (PF_SPINNER,"aeValue", ("ALPHA_MATTING_ERODE_SIZE"), 15, (15,100,1))
    domain=("gimp20-python", gimp.locale_directory))

I have tried to install rmbg in a variety of 'buntu versions 22.04 / 20.04 / 18.04 without success always get a incompatible version error. That is me stuck.

The only thing I can suggest for your appimage is either put a symbolic link to it into /usr/bin or even the whole appimage file in /usr/bin and avoid the dot-slash

The appimage is the same as a regular Gimp, it will open files tacked on after the gimp command so it should work with those parameters in the script.

This an example running the appimage which is in /usr/bin and opening two image files.

You are probably better off asking on gimpchat.
Thanks Admin.

It is working now. But rembg is not acting. ie, the cycle completes but the background is not removed. Since nothing was happening, I delete the part where the plugin removes the copy from the tmp folder. And, I was able to see the input picture as is in the tmp folder.
I would say if you are using the Daniel Gatis developed background remover then you don't need a Gimp plugin. If you want it for videos, this works for me. Convert video to PNGs using ffmpeg. Then use a bash script to remove their backgrounds with rembg via anaconda. There are lots of background removers on github. Some use an online server but I want to do it locally not upload and d'load thousands of images. Also get a clear image stream with a neutral background like on a beach. Or in the sky. The AI is not that smart Smile

I experimented with just removing a green screen from video clips. There are probably thousands of free to use online. This is easy to do in kdenlive but that app only makes videos Sad Its PNG export is just huge bloat.


Now I found a video editor where I can import a thousand PNGs, remove their backgrounds and then export them as PNGs. It's not FOSS so I won't post it's name here.
Thanks @Tas_mania

I am comfortably using the CLI which can deal with one photo or a group of photos in a folder.

I was wondering how to use it with GIMP and define what to remove and what not.

Forum Jump: