Composite multiple images with a single one

  • Pekka

    Pekka - 2012-11-14

    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.

  • Bob Friesenhahn

    Bob Friesenhahn - 2012-11-15

    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
      outfile=`echo $infile | sed -e 's/image/result/ ; s/\..*//'`.jpg
      gm composite $infile background.jpg $outfile

    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.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks