Skip to content

Instantly share code, notes, and snippets.

@pedroxs
Created March 22, 2024 13:35
Show Gist options
  • Save pedroxs/992daef26cef0376f62aafc5d7d66b1d to your computer and use it in GitHub Desktop.
Save pedroxs/992daef26cef0376f62aafc5d7d66b1d to your computer and use it in GitHub Desktop.
Helper tool to remove background from images
#!/bin/bash
# Remove background from images
# use zenity to read a directory and store in a variable
dir=$(zenity --file-selection --directory --title="Escolha uma pasta" --filename="$HOME/")
if [ -z "$dir" ]; then
exit
fi
# confirm the selected directory
zenity --question --text="Remover o fundo das imagens em: \n $dir?" --title="Confirmação" --ok-label="Sim" --cancel-label="Não"
if [ $? -ne 0 ]; then
exit
fi
# run docker image danielgatis/rembg with the selected directory
# and remove the background from all images in the directory
# using the same user and group id as the current user
docker run --rm -e OU=$(id -u) -e OG=$(id -g) -v $dir:/data --entrypoint='sh' danielgatis/rembg -elc '
mkdir -p /data/result
rembg p /data /data/result
chown -R $OU:$OG /data/result
'
# notify user that the process is complete
zenity --info --text="Remoção concluida. Imagens sem fundo estão em: \n $dir" --title="Concluido"
xdg-open $dir/result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment