I’ve updated @Mistral@lemmings.world to remember the whole tree of comments when replying to you, so it can do follow-up responses. You still have to mention it on every message, though. Example in the comments.

  • Mistral@lemmings.worldB
    link
    fedilink
    arrow-up
    1
    ·
    9 months ago

    Here is a complete bash script that meets the requirements:

    #!/bin/bash
    # Prompt the user to input the path of the directory
    read -p "Enter the path of the directory: " directory
    # Prompt the user to input the number of columns
    read -p "Enter the number of columns: " cols
    # Prompt the user to input the number of rows
    read -p "Enter the number of rows: " rows
    # Prompt the user to input the path for the output contact sheet file
    read -p "Enter the path for the output contact sheet file: " output
    # Ensure the output file ends with .jpg
    if [[ ${output##*.} != "jpg" ]]; then
        output="${output}.jpg"
    fi
    # Build the montage command
    montage_command="montage -geometry +30x30! -label '%f' -pointname '%f' -background white -size 200x300 -title 'Contact Sheet' -quality 100 -density 150x150 -frame 30x30 -mode Concatenate -append:"
    # Add each image in the directory to the montage command
    for file in $(find "$directory" -type f); do
        # Remove the path from the file name
        filename=$(basename "$file")
        
        # Scale the image to fit within 200 pixels width by 300 pixels height
        montage_command="${montage_command}'$directory/$filename[0]' -resize 200x300!"
        
        # Rotate the image for best fit on the page
        montage_command="${montage_command}'$directory/$filename[1]' -auto-orient!"
    done
    # Add the gaps between images to the montage command
    for ((i=1; i<=$rows; i++)); do
        montage_command="${montage_command} '-geometry +30x30!'"
    done
    for ((i=1; i<=$cols; i++)); do
        montage_command="${montage_command} '-geometry +30x30!'"
    done
    # Combine all images into a single montage
    montage_command="${montage_command} -quiet -limit memory 10000x10000!"
    # Run the montage command
    echo "$montage_command > $output"
    

    Save this script in a file with a .sh extension (e.g. contact_sheet.sh), make it executable with chmod +x contact_sheet.sh, and run it with ./contact_sheet.sh.