|
|
@@ -0,0 +1,37 @@
|
|
|
+#!/bin/bash
|
|
|
+
|
|
|
+if [[ $1 == "" || $2 == "" ]]; then
|
|
|
+ echo "Usage: $0 [input-file] [output-file]"
|
|
|
+ exit -1;
|
|
|
+fi
|
|
|
+
|
|
|
+if [ ! -f $1 ]; then
|
|
|
+ echo "$1 input file not exists."
|
|
|
+ exit -1;
|
|
|
+fi
|
|
|
+
|
|
|
+if [ -f $2 ]; then
|
|
|
+ echo "$2 output file already exists."
|
|
|
+ exit -1;
|
|
|
+fi
|
|
|
+
|
|
|
+if [ ! -d ~/.rembg ]; then
|
|
|
+ echo "Installing rembg in ~/.rembg"
|
|
|
+
|
|
|
+ python -m venv ~/.rembg
|
|
|
+ ~/.rembg/bin/pip install rembg[gpu,cli]
|
|
|
+fi
|
|
|
+
|
|
|
+if [ ! -d /tmp/prepare-image ]; then
|
|
|
+ mkdir /tmp/prepare-image
|
|
|
+fi
|
|
|
+
|
|
|
+echo "Processing image $1..."
|
|
|
+
|
|
|
+temp=/tmp/prepare-image/$(basename $2).png
|
|
|
+
|
|
|
+~/.rembg/bin/rembg i $1 $temp
|
|
|
+magick $temp -background white -flatten -trim $2
|
|
|
+rm $temp
|
|
|
+
|
|
|
+echo "Saved as $2."
|