prepare-image 668 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. if [[ $1 == "" || $2 == "" ]]; then
  3. echo "Usage: $0 [input-file] [output-file]"
  4. exit -1;
  5. fi
  6. if [ ! -f $1 ]; then
  7. echo "$1 input file not exists."
  8. exit -1;
  9. fi
  10. if [ -f $2 ]; then
  11. echo "$2 output file already exists."
  12. exit -1;
  13. fi
  14. if [ ! -d ~/.rembg ]; then
  15. echo "Installing rembg in ~/.rembg"
  16. python -m venv ~/.rembg
  17. ~/.rembg/bin/pip install rembg[gpu,cli]
  18. fi
  19. if [ ! -d /tmp/prepare-image ]; then
  20. mkdir /tmp/prepare-image
  21. fi
  22. echo "Processing image $1..."
  23. temp=/tmp/prepare-image/$(basename $2).png
  24. ~/.rembg/bin/rembg i $1 $temp
  25. magick $temp -background white -flatten -trim $2
  26. rm $temp
  27. echo "Saved as $2."