Objective
Throwing images to a folder and the script generates a single image with all the images that were copied and this image is optimized.
Script with ImageMagick
The main script is create with imagemagick. I find a good example in this Link.
This is the code:
convert -append IMG_*.JPG out.jpg
The append command is the one that allows you to join the images. If you use -append joins them horizontally and if you use +append the images align vertically.
the optimized version is this one:
convert -append IMG_*.JPG -quality 65 -strip -interlace JPEG out-ok.jpg
Trigger folder
We open the Automator program in MacOS and create a new folder action
Then we select the folder where the action is to be performed.
We needd The run shell script action to add our script and the view results to get some information when we running the automator actions.
You will end with a worflow like this:
The script grow a little bit:
if [ -x /usr/libexec/path_helper ]; then
/usr/libexec/path_helper -s`
eval
fi
if [ -f "$HOME"/.profile ]; then
source "$HOME"/.profile
elif [ -f "$HOME"/.bash_profile ]; then
source "$HOME"/.bash_profile
elif [ -f "$HOME"/.bashrc ]; then
source "$HOME"/.bashrc
fi
convert -append /Users/username/Desktop/prueba/IMG_*.JPG -quality 65 -strip -interlace JPEG /Users/username/Desktop/prueba/out-ok.jpg
`
The if part is just a way to catch all the posible path to let Automator see the commands in zsh. You can test another options like:
sometimes with a link to this file work
source ~/.zshrc
if you want to know more about this error in Automator follow this question in stackexchange.
The second part of the script is the same script we see at begining but with absolute links to image pattern (IMG_*.JPG) and to final image.
Test the folder action in Automator and when it work without any error there is a last step.
Folder action setup
Now you need to link the folder action to the folder whe image will be process. Select the folder and with the right mouse show options. Select Folder action setup and will pop up with a warnig about Confirm Service, touch the service button.
then in the right part of this window touch the + button and select the folder action you create and save in Automator.
Check the action is selected and if all the steps are correct the script will run and images will be join in this folder!
Top comments (0)