Composite multiple images with a single one

Help
Pekka
2012-11-14
2013-03-27
  • Pekka
    Pekka
    2012-11-14

    Hello
    I'm trying to combine multiple images with a specific one (background.jpg) so that each combination results in a new image (or overwrites the first image). This works:
    gm composite image1.png background.jpg result1.jpg
    gm composite image2.png background.jpg result2.jpg
    gm composite image3.png background.jpg result3.jpg
    , but how do I do this for every image in a folder? I hoped something like this would work:
    gm composite *.png background.jpg
    the output should probably have sort of running numbering, but I don't know how to do it.
    Thank you in advance.

     
  • What type of operating system are you using?  If you are using a Unix/Linux type system, or Cygwin under Windows you could do something like

    for infile in image*.png
    do
      outfile=`echo $infile | sed -e 's/image/result/ ; s/\..*//'`.jpg
      gm composite $infile background.jpg $outfile
    done

    This uses the Unix shell (e.g. bash).

    Composite won't work with the auto-numbering like you want because all of the input files would be composited together so there would be just one output file.

     
  • Pekka
    Pekka
    2012-11-15

    Currently I'm using Windows. I installed Cygwin as you suggested and ran your code. It worked just like I wanted.
    Thank you for the solution.