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.

  • @MistralB
    link
    19 months ago

    Here’s a complete bash script that accomplishes the tasks you’ve outlined:

    #!/bin/bash
    
    # Prompt user for directory path
    echo "Enter directory path:"
    read dir_path
    
    # Prompt user for number of columns
    echo "Enter number of columns:"
    read cols
    
    # Prompt user for number of rows
    echo "Enter number of rows:"
    read rows
    
    # Calculate total number of images and total width
    total_images=$(ls -1 "$dir_path"/* | wc -l)
    total_width=$((cols * 230)) # 200px for each image plus 30px gap
    
    # Check if total width is greater than 300px, if so, increase rows
    if (( $(($total_width / 300)) < $rows )); then
        rows=$(($total_images / $cols))
        if (( $(($total_images % $cols)) != 0 )); then
            rows=$(($rows + 1))
        fi
    fi
    
    # Calculate total height
    total_height=$((rows * 300))
    
    # Prompt user for output file path
    echo "Enter output file path:"
    read output_file
    
    # Create contact sheet using Montage
    montage -geometry +0+0 -label "%t" -pointsize 20 -background white \
            $(ls -1 "$dir_path"/* | sed '1d' | awk "NR==$total_images{print}") \
            -tile "$colsx$rows" -geometry 200x300\> \
            "$output_file"
    
    echo "Contact sheet created successfully!"
    

    Save the script as a file (e.g., contact_sheet.sh), make it executable (chmod +x contact_sheet.sh), and run it (./contact_sheet.sh). It will prompt you for the necessary inputs and create the contact sheet file in the specified output path.