I'd like to automate the creation of collages

Each day I create about 50 mockups of a product in 9 different colours. With these 9 different colours, I create a collage of the 9 square images, resulting in a square 3x3 collage with no space, just simple stitching of the images is all that's needed. They need to be in a specific order and the output file size must be less than 500kb, with the output image name be 'b'. Is this possible with automator? Currently I'm using a web app to carry out the task but it is always manual. Any help would be greatly appreciated! (pictured is the 9 colours and the output collage)

MacBook Pro 16", macOS 10.15

Posted on Apr 9, 2020 5:07 AM

Reply
Question marked as Top-ranking reply

Posted on Apr 11, 2020 5:17 AM

The Zsh script that I have written will expect the parent folder as a selection, and then it will recursively drill down through every product name folder, and only run montage on the contents of each mockup folder, where it deposits the B.jpg result.


zsh source:


#!/bin/zsh

PARENT="${1:a}"
# JPEG quality
QUALITY=50
PPI=300
# so this script knows where the ImageMagick montage binary is located
source ~/.zshrc

# recursively get just the folders paths (F) in the parent directory
for adir in ${PARENT}/**/(F)
do
    # only perform a montage on the contents of the mockups folder(s)
    # and ignore any other folder or its contents
    [[ ${adir%/} = ${PARENT}  || ${adir:a:t:r} != "mockups" ]] && continue
    montage ${adir}[l-t].jpg -geometry +3+3 -tile 3x3 -units PixelsPerInch -density ${PPI} \
        -adjoin -strip -quality ${QUALITY} -background black ${adir}/B.jpg
done
exit



AppleScript source:


use scripting additions
on run {input, parameters}
	
	display dialog "Mockup montages complete" with title "Montage Processing"
	return
end run



I have tested this in an Automator application and it works as expected. The Automator solution uses three actions in its workflow:

  1. Library : Files and Folders : Ask for Finder Items
    1. Select the parent folder
  2. Library : Utilities : Run Shell Script
    1. The previous Zsh script that processes the product mockup folders
  3. Library : Utilities : Run AppleScript
    1. A dialog letting you know that montage processing is done


When you open Automator, choose the Desktop, and then click New Document. A type of document panel will then appear and you want to choose Application, and then click Choose.


Automator will then open into a three panel presentation left to right : 1) Libraries 2) Library actions and 3) a large workflow window. You drag and drop the preceding bold named actions in order onto the workflow window.

  1. Ask for Finder Items
    1. Set the Start at: to Desktop
    2. Set the Type to Folder (only)
    3. Do not select Multiple Selection
  2. Run Shell Script
    1. Shell is /bin/zsh
    2. Pass input: as arguments
      1. This will allow the folder you selected to pass into the zsh script as $1.
    3. Replace all default content in the Run Shell Script window with the copy/pasted Zsh script from above that follows Zsh source in bold.
  3. Run AppleScript
    1. Replace the entire default content with the AppleScript from above that follows AppleScript source in bold
    2. Click the hammer icon in the Run AppleScript
  4. Save the Automator application to your Desktop with a meaningful name
  5. Quit Automator
  6. Double-click the Automator application on the Desktop to run it.


Looks like this when done:


55 replies
Question marked as Top-ranking reply

Apr 11, 2020 5:17 AM in response to palnoch

The Zsh script that I have written will expect the parent folder as a selection, and then it will recursively drill down through every product name folder, and only run montage on the contents of each mockup folder, where it deposits the B.jpg result.


zsh source:


#!/bin/zsh

PARENT="${1:a}"
# JPEG quality
QUALITY=50
PPI=300
# so this script knows where the ImageMagick montage binary is located
source ~/.zshrc

# recursively get just the folders paths (F) in the parent directory
for adir in ${PARENT}/**/(F)
do
    # only perform a montage on the contents of the mockups folder(s)
    # and ignore any other folder or its contents
    [[ ${adir%/} = ${PARENT}  || ${adir:a:t:r} != "mockups" ]] && continue
    montage ${adir}[l-t].jpg -geometry +3+3 -tile 3x3 -units PixelsPerInch -density ${PPI} \
        -adjoin -strip -quality ${QUALITY} -background black ${adir}/B.jpg
done
exit



AppleScript source:


use scripting additions
on run {input, parameters}
	
	display dialog "Mockup montages complete" with title "Montage Processing"
	return
end run



I have tested this in an Automator application and it works as expected. The Automator solution uses three actions in its workflow:

  1. Library : Files and Folders : Ask for Finder Items
    1. Select the parent folder
  2. Library : Utilities : Run Shell Script
    1. The previous Zsh script that processes the product mockup folders
  3. Library : Utilities : Run AppleScript
    1. A dialog letting you know that montage processing is done


When you open Automator, choose the Desktop, and then click New Document. A type of document panel will then appear and you want to choose Application, and then click Choose.


Automator will then open into a three panel presentation left to right : 1) Libraries 2) Library actions and 3) a large workflow window. You drag and drop the preceding bold named actions in order onto the workflow window.

  1. Ask for Finder Items
    1. Set the Start at: to Desktop
    2. Set the Type to Folder (only)
    3. Do not select Multiple Selection
  2. Run Shell Script
    1. Shell is /bin/zsh
    2. Pass input: as arguments
      1. This will allow the folder you selected to pass into the zsh script as $1.
    3. Replace all default content in the Run Shell Script window with the copy/pasted Zsh script from above that follows Zsh source in bold.
  3. Run AppleScript
    1. Replace the entire default content with the AppleScript from above that follows AppleScript source in bold
    2. Click the hammer icon in the Run AppleScript
  4. Save the Automator application to your Desktop with a meaningful name
  5. Quit Automator
  6. Double-click the Automator application on the Desktop to run it.


Looks like this when done:


Apr 9, 2020 7:39 AM in response to palnoch

There are no automator actions that can do collage/montages for you.


It seems like the imagemagick tool's montage command can do this for you. I replicated your color objects as gears inside nine, one-inch, 300 dpi squares. I then performed the the following inside of the directory with the images. The *.jpg takes advantage of UNIX's collation sequence so images are processed in alphabetic order:


montage *.jpg -geometry +3+3 -tile 3x3 -adjoin -background black B.jpg


Before:


After:


And a closer look at B.jpg (70 Kb on disk):

Apr 11, 2020 11:14 AM in response to VikingOSX

#!/bin/zsh

PARENT="${1:a}"
# JPEG quality
QUALITY=50
PPI=300
# so this script knows where the ImageMagick montage binary is located
source ~/.zshrc

# recursively get just the folders paths (F) in the parent directory
for adir in ${PARENT}/**/(F)
do
    # only perform a montage on the contents of the mockups folder(s)
    # and ignore any other folder or its contents
    [[ ${adir%/} = ${PARENT}  || ${adir:a:t:r:u} != "MOCKUPS" ]] && continue
    montage ${adir}[l-t].jpg -geometry +3+3 -tile 3x3 -units PixelsPerInch -density ${PPI} \
        -adjoin -strip -quality ${QUALITY} -background black ${adir}/B.jpg
done
exit

Apr 10, 2020 8:43 AM in response to palnoch

You will need to escape the white-space in your path:


montage /Users/charlie/Documents/Work/Neon\ Beach/DESIGNS/SHAPES/Psychadelic/SHAPE_Cocktails/MOCKUPS/[l-t].jpg -geometry +3+3 -tile 3x3 -units PixelsPerInch -density 300 -adjoin -background black B.jpg


Try the above command, though easier if you change directory to that location and then just run the montage command there.


% cd ~/Documents/Work/Neon\ Beach/DESIGNS/SHAPES/Psychadelic/SHAPE_Cocktails/MOCKUPS
% montage [l-t].jpg -geometry +3+3 -tile 3x3 -units PixelsPerInch -density 300 -adjoin -background black B.jpg

Apr 10, 2020 6:49 AM in response to palnoch

You got ImageMagick installed in your ~/bin folder. Now you need to open the hidden ~/.bash_profile in an editor (vim, vi, TextEdit (plain text only), BBEdit, or some other editor). Then perform step 3 items, save the ~/.bash_profile, and then step 4.


After the above, you should be able to run the ImageMagick commands in the Terminal, including montage.

Apr 10, 2020 9:12 AM in response to palnoch

You copied the scrollable command-line entry from my previous post up to -backg, and montage dutifully wrote the result into a file named -backg. Instead, when you encounter those scrollable entries, triple-click and then copy/paste into the Terminal and you will get the full command — which would have placed the result in B.jpg.


Triple-click this following entry and paste into the Terminal followed by a return.


montage [l-t].jpg -geometry +3+3 -tile 3x3 -units PixelsPerInch -density 300 -adjoin -background black B.jpg


If your images have any border on them (e.g. white border) then that will explain the white line matrix.

Apr 10, 2020 3:47 PM in response to palnoch

The short answer is yes. A zsh script can get the individual folders in a parent directory, and apply the montage to each of these children folders images [l-t].jpg just as before with the familiar montage command line.


Are there images in the parent folder, or confined solely to the children folders? I am testing something right now, but having been up since 5am, i am fading, and this likely will get resolved tomorrow. The script is short and reasonably uncomplicated.


Is the folder structure more complicated that the following, where TestX would be the parent folder?

Apr 11, 2020 11:13 AM in response to palnoch

Copy the entire contents of the Zsh script from the Run Shell Script action to the clipboard. Click the <> item on this editor's bottom toolbar, and click in that gray area, then paste from the clipboard. Click the <> button again, and post here.


The line that includes: source ~/.zshrc should make your PATH information available to the script so that it finds the montage command without forcing an explicit path to the command.


I am also out of town today, so my image test environment is not with me.

Apr 10, 2020 3:39 AM in response to palnoch

There is a discussion of homebrew just before the compiled binary download that is ImageMagick-x86_64-apple-darwin19.3.0.tar.gz. The latter, in reality is the recent ImageMagick 7.0.10 build once it is installed. In the Terminal do the following:

  1. mkdir ~/bin
  2. Download ImageMagick-x86_64-apple-darwin19.3.0.tar.gz. This should be in your Downloads folder.
    1. cd ~/Downloads
    2. tar xzf ImageMagick-x86_64-apple-darwin19.3.0.tar.gz -C ~/bin
      1. Unpacks the tar hierarchy as ~/bin/ImageMagick-7.0.10
  3. Add the following to ~/.bash_profile
    1. export MAGIC_HOME="$HOME/bin/ImageMagic-7.0.10"
    2. export PATH=$HOME:$HOME/bin:$MAGIC_HOME/bin:$PATH"
    3. export DYLD_LIBRARY_PATH="$MAGIC_HOME/lib/"
  4. source ~/.bash_profile


I have done all of the above steps, and when you launch Terminal in the future, it will read the ~/.bash_profile and set the environment variables needed by ImageMagick.


The numeric information in that ImageMagick tar file (e.g. 19.3.0) appears to be tracking the uname -r version of Catalina just prior to 10.15.4, so it is 64-bit compatible there too.


I have run Malwarebytes v4.3.5 after this installation and nothing was found.



Apr 9, 2020 7:35 AM in response to palnoch

palnoch wrote:

Each day I create about 50 mockups of a product in 9 different colours. With these 9 different colours, I create a collage of the 9 square images, resulting in a square 3x3 collage with no space, just simple stitching of the images is all that's needed. They need to be in a specific order and the output file size must be less than 500kb, with the output image name be 'b'. Is this possible with automator? Currently I'm using a web app to carry out the task but it is always manual. Any help would be greatly appreciated! (pictured is the 9 colours and the output collage)
https://discussions.apple.com/content/attachment/e92dca50-d33e-4632-b955-0fd6d224dbca



Sound like you need a better third party software (?)


https://apps.apple.com/us/app/picture-collage-maker-lite/id500623480?mt=12


https://apps.apple.com/us/app/photo-collage-maker-collagefactory-free/id620343399?mt=12


https://themacbeginners.com/make-photo-collage-mac/


https://www.pearlmountainsoft.com/collageit-for-mac/

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

I'd like to automate the creation of collages

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.