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

Apr 10, 2020 9:19 AM in response to VikingOSX

You legend! It's not too much of an issue but even if i change the pixelsperinch to 150, or 72, the output file size is still 3mb +


Do you know any way to output the file smaller than 1mb? It's just I'm doing hundreds of these and I need page load speed to be optimal. You've been amazing help, I'd like to donate for your time if possible

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

You must have large source images. Each of my 1-inch square, 300 dpi images, even at 100% JPG quality — was 20KB, and the final, 300 dpi B.jpg is only 70 KB.


Try this, and see what the size reduction is in Bnew.jpg:


convert B.jpg -strip -quality 90 Bnew.jpg


You can also combine these in the montage command line:

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



Apr 10, 2020 10:09 AM in response to VikingOSX

Now I'm getting started with this automation stuff, I'm wondering if it's possible to run a program that gathers the names of all the folders in the folder 'psychadelic' and then exucutes the line:

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


on all of them?

Apr 10, 2020 3:06 PM in response to VikingOSX

Now I'm getting started with this automation stuff, I'm wondering if it's possible to run a program that gathers the names of all the folders in the folder 'psychadelic' and then exucutes the line:

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


on all of them?

Apr 12, 2020 4:49 AM in response to palnoch

I am pleased that you have this working now. That is my payment.


The only reason to keep Xcode installed would be if you ever wanted to upgrade to a newer version of ImageMagick when it becomes available, or newer versions of its dependent libraries that brew installed along with it. Those too would be compiles requiring Xcode when you performed the series of homebrew commands (update, upgrade) I mentioned previously. I typically run brew update/upgrade/cleanup about twice a month.


I also used homebrew to install the tree program that produced those folder hierarchy displays.


brew install tree
tree -N ./TestX
man tree




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.