folder="./yoga_images" # replace with path to your image folder # create a new folder to store the converted images mkdir -p "$folder/text" # loop through all the files in the folder for file in "$folder"/*; do # get the filename without path or extension filename=$(basename "$file") text="${filename%%_*}" # check if the image is larger than 1200x800 dims=$(identify -format "%w %h" "$file") width=$(echo "$dims" | awk '{print $1}') height=$(echo "$dims" | awk '{print $2}') if [ "$width" -gt 1200 ] || [ "$height" -gt 800 ]; then # crop the image to 1200x800 convert "$file" -crop 1200x800+0+0 +repage "$file" fi # convert the image to PNG and add text to the top-left corner convert "$file" -background black -undercolor blue -fill white -gravity NorthWest -pointsize 20 -annotate +10+10 "$text" "$folder/text/$filename.png" done #create a new folder to store the resized images #mkdir -p "$folder/text" #extract up to first _ using bash #bash_convert_print_text_of_domain_on_png #for file in "$folder"/*; #do # dim=$(identify -format "%w" "$file") # ptsize=$(bc <<< "($dim / 30)") #ptsize=15 # filename=$(basename "$file") # text="${filename%%_*}" # extension="${filename##*.}" # convert "$file" -background black -undercolor blue -fill white -gravity NorthWest -pointsize $ptsize -annotate +10+10 "$text" -quality 100 "$folder/text/$filename.png" #done #folder="./yoga_images" # replace with path to your image folder # create a new folder to store the resized images #mkdir -p "$folder/text" # extract up to first _ using bash # bash_convert_print_text_of_domain_on_png # Parallelize the loop using parallel #parallel "dim={}; ptsize=$(bc <<< \"(\$dim / 30)\"); filename={}; text=\${filename%%_*}; extension=\${filename##*.}; convert {} -background black -undercolor blue -fill white -gravity SouthEast -pointsize \$ptsize -annotate +10+10 \$text -quality 100 $folder/text/\$filename.png" ::: "$folder"/* ::: $(identify -format "%w" "$folder"/*) #This script uses the parallel utility to parallelize the processing of the images in the yoga_images folder. #The script first creates a new folder called text within the yoga_images folder to store the resized images. #Next, the for loop that was in the original script is replaced by a call to the parallel command. #This command takes multiple inputs and executes a command in parallel for each input. #The inputs are passed as arguments to the parallel command using the ::: operator. #In this script, the inputs are the file names in the yoga_images folder and the width of each image. #The width is obtained using the identify command with the -format option set to "%w". #The command that is executed in parallel is specified within the quotes following the parallel command. #It sets the dimensions and size of the text to be added to each image, extracts the text from the file name, and then uses the convert command to add the text to each image. The resulting images are saved in the text folder within the yoga_images folder. #By parallelizing the processing of the images, the script will run faster as multiple images can be processed simultaneously.