1

So I've been working at this for a while and I think I'm ready to give up. I trying to process sub-folders with imagemagick's montage to create contact sheets.

This is basically as close as I've gotten:

find '/dir-with-spaces/' -type f -regex ".*\.\(JPG\|jpg\|jpeg\|JPEG\)" -print0 | \
     while IFS= read -r -d $'\0' line;\
       do \
         montage "$line" "${line}".jpg; \
       done

Using this command, Montage processes each picture individually. The behaviour I want is for find to search down the lowest directory for pictures, back up, send that all to montage and then continue on the the next folder with the resulting contact sheet named with the entire folder tree.

i.e.:

/media/pictures/folder1/folder2/pic1.jpg...pic100.jpg --> media-pictures-folder1-folder2.jpg

A few other things I've tried to come up with are:

#This just hangs montage forever
find . -name *.jpg -printf '%h\n' | sort -u | xargs -I {} montage {}/*

#I need a "+" here for -execdir, but I don't think I can use it with montage's argument structure.
find . -name *.jpg -execdir montage {} test.jpg \;

The directory structure is something like:

folder1
  folder1_1
    folder1_2
      folder1_3
        *.jpg
folder2
  folder2_1
    *.jpg
folder3
  folder3_1
    folder3_2
      folder3_4
        folder3_5
          *.jpg

Running Ubuntu 14.10

Any help on this would be greatly appreciated.

1
  • Welcome to AskUbuntu! ;-) Could you please give us a bit more information like: what version of Ubuntu you're running? What the directory structure is that you want to run through? Please edit your question and add this information...
    – Fabby
    Feb 6, 2015 at 10:46

1 Answer 1

2

I've had a similar problem but without the folders on file name part. Bellow is a script that do what you're asking. Change base to your starting folder. The montage use options -geometry to set the tile size in px «width»x«height» and -tile for number of tiles «columns»x«lines».

#!/bin/bash -eu

base="/usr/share/icons/hicolor"
find "$base" -type d | while read fld
do
  [ $fld == $base ] && continue
  echo ">>> $fld"
  aux="${fld//\//_}"
  aux="${aux:1}"
  find "$fld" -type f -maxdepth 1 -iregex ".*\.\(jpg\|jpeg\|gif\|svg\|png\)" > "/tmp/${aux}.txt"

  if [ -s "/tmp/${aux}.txt" ]
  then
    montage "@/tmp/${aux}.txt" -geometry 64x -tile 3x "${aux}.jpg"
  fi
  rm "/tmp/${aux}.txt"
done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .