1

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.

Arno Nuehm
  • 17
  • 6

1 Answers1

0

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
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Hi Mark, thanks for your answer. Quite interesting! How could I automatically scan the folder and process all images like that? – Arno Nuehm Mar 01 '17 at 13:36
  • If you are on macOS, it is easiest to install **ImageMagick** with **homebrew**, where it is just `brew install imagemagick`. – Mark Setchell Mar 01 '17 at 13:39
  • It depends on your OS. – Mark Setchell Mar 01 '17 at 13:40
  • I just installed ImageMagick now on Win10 and tested it: convert Filename1-FB.jpg -gravity center -background ping -extent 200x100% ( Filename1-SP.jpg Filename1-SP.jpg +append ) -append result.jpg -- Works great, but I wish to have to colored version in double size so that it covers the width of the two other versions. – Arno Nuehm Mar 01 '17 at 13:45
  • Ah, i did some Google searching now and got my result: convert Filename1-FB.jpg -gravity center -background pink -resize 200%x200% ( Filename1-SW.jpg Filename1-SP.jpg +append ) -append result.jpg – Arno Nuehm Mar 01 '17 at 13:50
  • But I need this one only for landscape orientated images. For portrait orientated images I would need them side by side. – Arno Nuehm Mar 01 '17 at 13:51
  • I have updated the code for Windows to the best of my (poor) Windows BATCH skills - I hope you can see how it works. – Mark Setchell Mar 01 '17 at 16:23
  • You may need to double up the percent signs in `-sepia-tone 80%%` - I am not sure. – Mark Setchell Mar 01 '17 at 20:50