|
|
#!/bin/bash |
|
|
|
|
|
if [ -z "$BASH_VERSION" ]; then |
|
|
echo "This script requires Bash to run." |
|
|
exit 1 |
|
|
fi |
|
|
|
|
|
image_ext=("jpg" "jpeg" "png" "bmp" "gif") |
|
|
|
|
|
has_images() { |
|
|
local folder="$1" |
|
|
for ext in "${image_ext[@]}"; do |
|
|
shopt -s nullglob |
|
|
files=("$folder"/*."$ext") |
|
|
shopt -u nullglob |
|
|
if [ ${#files[@]} -gt 0 ]; then |
|
|
return 0 |
|
|
fi |
|
|
done |
|
|
return 1 |
|
|
} |
|
|
|
|
|
if [ ! -d "input" ]; then |
|
|
echo "The 'input' folder does not exist. Please run the folder creation script first." |
|
|
read -p "Press Enter to continue..." |
|
|
exit 1 |
|
|
fi |
|
|
|
|
|
all_folders_have_images=true |
|
|
|
|
|
for folder in input/*/; do |
|
|
if [ -d "$folder" ]; then |
|
|
if has_images "$folder"; then |
|
|
echo "The folder \"${folder}\" contains images." |
|
|
else |
|
|
echo "The folder \"${folder}\" does not contain any images." |
|
|
all_folders_have_images=false |
|
|
fi |
|
|
fi |
|
|
done |
|
|
|
|
|
if [ "$all_folders_have_images" = false ]; then |
|
|
echo |
|
|
echo "Please place at least one image in each folder. A minimum of 20 images per folder is recommended." |
|
|
read -p "Press Enter to continue..." |
|
|
exit 1 |
|
|
fi |
|
|
|
|
|
if [ ! -d "output" ]; then |
|
|
mkdir "output" |
|
|
echo "'output' folder created." |
|
|
else |
|
|
echo "The 'output' folder already exists." |
|
|
fi |
|
|
|
|
|
for folder in input/*/; do |
|
|
if [ -d "$folder" ]; then |
|
|
name=$(basename "$folder") |
|
|
output_path="output/$name" |
|
|
|
|
|
if [ ! -d "$output_path" ]; then |
|
|
mkdir "$output_path" |
|
|
echo "Folder '$output_path' created." |
|
|
else |
|
|
echo "Folder '$output_path' already exists." |
|
|
fi |
|
|
|
|
|
for sub in img log model; do |
|
|
subfolder="$output_path/$sub" |
|
|
if [ ! -d "$subfolder" ]; then |
|
|
mkdir "$subfolder" |
|
|
echo "Folder '$subfolder' created." |
|
|
else |
|
|
echo "Folder '$subfolder' already exists." |
|
|
fi |
|
|
done |
|
|
|
|
|
special_folder="$output_path/img/30_${name} person" |
|
|
if [ ! -d "$special_folder" ]; then |
|
|
mkdir "$special_folder" |
|
|
echo "Folder '$special_folder' created." |
|
|
else |
|
|
echo "Folder '$special_folder' already exists." |
|
|
fi |
|
|
fi |
|
|
done |
|
|
|
|
|
for folder in input/*/; do |
|
|
if [ -d "$folder" ]; then |
|
|
name=$(basename "$folder") |
|
|
source_folder="$folder" |
|
|
destination_folder="output/$name/img/30_${name} person" |
|
|
|
|
|
echo "Copying images from \"$source_folder\" to \"$destination_folder\"..." |
|
|
|
|
|
for ext in "${image_ext[@]}"; do |
|
|
shopt -s nullglob |
|
|
files=("$source_folder"/*."$ext") |
|
|
shopt -u nullglob |
|
|
if [ ${#files[@]} -gt 0 ]; then |
|
|
cp -u "${files[@]}" "$destination_folder"/ |
|
|
fi |
|
|
done |
|
|
|
|
|
echo "Images copied for \"$name\"." |
|
|
fi |
|
|
done |
|
|
|
|
|
echo |
|
|
echo "Folders created and images copied successfully!" |
|
|
read -p "Press Enter to continue..." |
|
|
|