-1

I have to acomplish the following task: Two square, equally sized png images have to be put together side by side and exported as a combined image. This has to be done to hundreds of pairs in a folder with endings "_1" and "_2"

I think this can be done in Gimp with Pytho-Fu, but trying to understand the fundamentals of scripting for Gimp is a bit overwhelming on a tight schedule and I really just need a solution for this single task. I would really appreciate you to point me in the right direction with this.

(If there is a simpler solution than using Gimp, please let me know. It should run on Linux and ideally be able to be executed from bash.

merging two pictures

adrifromhh
  • 11
  • 4

2 Answers2

0

After xenoid's recommendation: I found ImageMagick's syntax and documentation to be a horrible mess less than optimal, so I'll share how I got it done:

with Ubuntu 18.04.04:

montage -tile x1 -geometry +0+0  input1.png input2.png output.png

The whole thing (probably not interesting for anyone else...)

#! /bin/bash

input="./Input/"
output="./Output/"

# add to output filename
prefix="CIF_"
postfix="_2"

# get file list
readarray -d '' RRA < <(find $input -regextype posix-egrep -regex '(.*)?_1_cr\.png$' -print0)
echo "Merging ${#RRA[@]} images.."

# remove directory from filename
RRA=( "${RRA[@]##*/}" )

# strip last part of filename: "_1_cr.png"
RRA=( "${RRA[@]/%_1_cr\.png/}" )

# merge images
for fall in "${RRA[@]}";do

    # check if there are two images to merge for current case
    if test -f "$input${fall}_2_cr.png"; then
        echo "${fall}"
        montage -tile x1  -tile-offset +10 -geometry +0+0  -border +20+20 -bordercolor white $input${fall}_1_cr.png $input${fall}_2_cr.png $output$prefix${fall}$postfix.png
    else
        echo "${fall} - no second image found"
    fi
    
done 
adrifromhh
  • 11
  • 4
0

With ImageMagick, you can loop over each pair and just do:

convert image_1.png image_2.png +append image_1_2.png

See

https://imagemagick.org/Usage/layers/#append


If you want space between them, then use +smush X, where X is the amount of space that you want. If you want them overlapped, then use a negative value for X. You can set the color of the space using -background color.

See https://imagemagick.org/script/command-line-options.php#smush

fmw42
  • 46,825
  • 10
  • 62
  • 80