Guest User

Add Random Background after Removal

a guest
Nov 6th, 2023
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.65 KB | Software | 0 0
  1. #!/bin/bash
  2.  
  3. for f in *.png; do
  4.     background=$(ls -1 ../backgrounds/*.jpg | shuf -n 1)
  5.     convert "$background" -resize "$(identify -format "%wx%h" "$f")^" -gravity center -extent $(identify -format "%wx%h" "$f") temp_background.jpg
  6.     convert temp_background.jpg "$f" -composite "output_$f"
  7.     rm temp_background.jpg
  8. done
  9.  
  10. Transparent foreground and Background image arrangement:
  11. parent_directory/
  12.     ├── foreground_images_folder/
  13.     │   ├── image1.png
  14.     │   ├── image2.png
  15.     │   └── script.sh
  16.     └── backgrounds/
  17.         ├── background1.jpg
  18.         ├── background2.jpg
  19.         └── ...
Advertisement
Add Comment
Please, Sign In to add comment