Browse Source

Script for prepare images for auctions.

Cixo Develop 1 year ago
parent
commit
cddee817b6
2 changed files with 66 additions and 0 deletions
  1. 29 0
      prepare-directory
  2. 37 0
      prepare-image

+ 29 - 0
prepare-directory

@@ -0,0 +1,29 @@
+#!/bin/bash
+
+if [[ $1 == "" || $2 == "" ]]; then
+    echo "Usage: $0 [input-directory] [output-directory]"
+    exit -1;
+fi
+
+if [ ! -d $1 ]; then
+    echo "$1 is not directory or not exists."
+    exit -1;
+fi
+
+if [ -d $2 ]; then
+    echo "$2 already exists, remove it first."
+    exit -1;
+fi
+
+mkdir $2
+
+for file in $1/*.{jpg,png,jpeg}; do
+    fullname=$(basename $file)
+    name=${fullname%.*}
+
+    if [[ $name == "*" ]]; then
+        continue
+    fi
+
+    prepare-image $1/$fullname $2/$fullname
+done

+ 37 - 0
prepare-image

@@ -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."