Search code examples
imagephotoshopphotoshop-script

Photoshop script batch action to place 3 images side by side and save as new image


I have a lot of images in a folder. They're named like this:

Filename1-FB.jpg <- coloured version of image 1
Filename1-SW.jpg <- black/white version of image 1
Filename1-SP.jpg <- sepia version of image 1
Filename2-FB.jpg <- coloured version of image 2
Filename2-SW.jpg <- black/white version of image 2
Filename2-SP.jpg <- sepia version of image 2
[...]

I would like to have those three versions of every image combined/merged into one image.

PERFECT (at least for landscape images) would be this:

[  FB  ]
[SW][SP]

But if this isn't working with Photoshop OR if it is a portrait orientated image this would be okay:

[FB][SW][SP]

It should be saved as a new image, maybe like this:

Filename1-FINAL.jpg
Filename2-FINAL.jpg
[...]

I tried to use the contact sheet function of Photoshop but this does not work without borders with landscape and portrait images.


Solution

  • If you can't achieve what you want with Photoshop scripting, you could consider using ImageMagick which is installed on most Linux distros and is available for macOS and Windows for free.

    Let's say your images are like this:

    Filename1-FB.jpg

    enter image description here

    Filename1-SW.jpg

    enter image description here

    Filename1-SP.jpg

    enter image description here

    Then you would just type this command into the Terminal (or Command Prompt on Windows):

    magick Filename1-FB.jpg -gravity center -background pink -extent 200x100% \
        \( Filename1-SW.jpg Filename1-SP.jpg +append \) -append result.jpg
    

    enter image description here

    Hopefully you can see that +append appends images side-by-side and -append appends images above and below. Also, I just chose pink to extend the canvas so you could see where it appears in the output image.

    Or, if you want all three in a row, side-by-side:

    magick Filename1-FB.jpg Filename1-SW.jpg Filename1-SP.jpg +append result.jpg
    

    enter image description here

    Also, you can see it is just a one-liner that could be put in a loop to do all images in the current directory.

    Note also, that ImageMagick could make the black and white and also the sepia versions automatically for you from the colour image:

    magick Filename1-FB.jpg -colorspace gray Filename1-SW.jpg
    magick Filename1-FB.jpg -modulate 100,0,100 -sepia-tone 80% Filename1-SP.jpg
    

    Some more notes that should help...

    If you want to know if an image is landscape or portrait, you can do this:

    magick image.jpg -format "%[fx:w>h?1:0]" info:
    

    if the image is landscape, it will print 1, if it is portrait it will print 0.


    If you want to get the width of an image, use:

    magick identify -format "%w" Filename1-SW.jpg
    400
    

    and change %w to %h for the height.


    Your Windows BATCH loop might look something like this - it is not my preferred scripting language:

    @ECHO OFF
    REM Loop through all colour pictures
    FOR /F %%f IN ( 'DIR /B *-FB.JPG' ) DO CALL :PROCESS %%f
    GOTO :EOF
    
    :PROCESS
       ECHO Processing file %1...
    
       SET this=%1
       SET core=%this:~0,-6%
       SET SW=%core%SW.jpg
       SET SP=%core%SP.jpg
       SET result=%core%FINAL.jpg
    
       REM Check if SW exists and create if not
       IF NOT exist %SW% magick %this% -colorspace gray %SW%
    
       REM Check if SP exists and create if not
       IF NOT exist %SP% magick %this% -modulate 100,0,100 -sepia-tone 80% %SP%
    
       REM Determine if image is landscape or portrait...
       REM Get width and height first
       FOR /F %%I IN ('magick %this% -format %%w info:') do set W=%%I
       FOR /F %%I IN ('magick %this% -format %%h info:') do set H=%%I
       IF %W% GTR %H% (
          magick %this% -resize 200x200% ( %SW% %SP% +append ) -append %result%
       ) ELSE (
          magick %this% %SW% %SP% +append %result%
       )
    GOTO :EOF