Append image to all images as background

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Append image to all images as background

Post by Rye »

I have the following files (they all [obviously] have transparency)
089.GIF
090.GIF
091.GIF
092.GIF
093.GIF
094.GIF
095.GIF
096.GIF
097.GIF
098.GIF
099.GIF
100.GIF
101.GIF
102.GIF
102_2.GIF
103.GIF
105.GIF
106.GIF
and one file that shall be appended as background to each of them
background.gif

I want the output files to be png files.

How/Can this be done as batch with imagemagick ?


ALTERNATIVE:
Apply each image as foreground ? (but keep the filename... somehow ?)
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Append image to all images as background

Post by fmw42 »

First question is what platform are you running? Windows are some Unix variant?

You can either write a script to loop over each of your images and composite the image over the background. See
http://www.imagemagick.org/Usage/layers/#convert
You will need to script the loop and that will be platform depending.

The other way is to put all your images into one folder except for the background, which you need to keep elsewhere. Then create a new empty folder for the resulting composites. Then use mogrify to do -draw with composite to put the single background image under each of the images in your folder. see
http://www.imagemagick.org/Usage/basics/#mogrify
http://www.imagemagick.org/Usage/basics ... fy_compose
http://www.imagemagick.org/Usage/layers/#draw
http://www.imagemagick.org/Usage/compose/#duff-porter
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Append image to all images as background

Post by Rye »

windows

the first suggestion sounds good.
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Append image to all images as background

Post by anthony »

Look then at
Windows Batch Processing
http://www.imagemagick.org/Usage/windows/#for_loops
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Append image to all images as background

Post by Rye »

Neat :)

Works like a charm:

Code: Select all

for %%x in (*gif) do convert background.png %%x -composite %%~nx.png


EDIT... thats what I thought at least...
for %%x in (*gif) do convert background.png %%x -composite %%~nx.png will now crash the cmd....
It worked like a charm before... ideas ?
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Append image to all images as background

Post by Rye »

Ok, sorry that I reopened this.

But this script *should* technically work:

Code: Select all

@echo off
set app=background.png
timeout 1 > nul
for %%n in (*.gif) do convert -page +0+0  %app%   -page +0+0 %%n -flatten %%n
but doesn't.... it is STUCK on the first image... any idea ?
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Post Reply