this post was submitted on 05 Apr 2024
26 points (84.2% liked)

General Discussion

12071 readers
3 users here now

Welcome to Lemmy.World General!

This is a community for general discussion where you can get your bearings in the fediverse. Discuss topics & ask questions that don't seem to fit in any other community, or don't have an active community yet.


🪆 About Lemmy World


🧭 Finding CommunitiesFeel free to ask here or over in: !lemmy411@lemmy.ca!

Also keep an eye on:

For more involved tools to find communities to join: check out Lemmyverse!


💬 Additional Discussion Focused Communities:


Rules

Remember, Lemmy World rules also apply here.0. See: Rules for Users.

  1. No bigotry: including racism, sexism, homophobia, transphobia, or xenophobia.
  2. Be respectful. Everyone should feel welcome here.
  3. Be thoughtful and helpful: even with ‘silly’ questions. The world won’t be made better by dismissive comments to others on Lemmy.
  4. Link posts should include some context/opinion in the body text when the title is unaltered, or be titled to encourage discussion.
  5. Posts concerning other instances' activity/decisions are better suited to !fediverse@lemmy.world or !lemmydrama@lemmy.world communities.
  6. No Ads/Spamming.
  7. No NSFW content.

founded 1 year ago
MODERATORS
 

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.

you are viewing a single comment's thread
view the rest of the comments
[–] Mistral@lemmings.world 1 points 7 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.