Append background to all images ?

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 background to all images ?

Post by Rye »

I have these images in a folder:


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 want to apply this as a background to all of them (as straightforward as possible):

background.png

Thanks in advance for any ideas.
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 background to all images ?

Post by fmw42 »

What platform?

Are the foreground images transparent? Are they the same size as the background image?

The simplest way is to use mogrify to put the background image under the other images.

see
http://www.imagemagick.org/Usage/basics/#mogrify
http://www.imagemagick.org/Usage/basics ... fy_compose
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Append background to all images ?

Post by Rye »

fmw42 wrote:What platform?

Windows

Are the foreground images transparent? Are they the same size as the background image?

yes and yes
The simplest way is to use mogrify to put the background image under the other images.

see
http://www.imagemagick.org/Usage/basics/#mogrify
http://www.imagemagick.org/Usage/basics ... fy_compose
Could you provide an example perhaps ?

I already tried, but the resulting script always fails horribly...
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 background to all images ?

Post by fmw42 »

Please upload 2 or 3 of your images and your background image to some free hosting service such as dropbox.com and put the URLs here. We need to see your images to know exactly what you are trying to do and if there are any issues with the images.

Note mogrify needs to have all your images placed in that folder. Then cd to the folder and use mogrify as described in those examples. However, I would suggest that you create a new directory for the output, so that you do not lose your original data.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Append background to all images ?

Post by fmw42 »

Your background image is surrounded by black and your other images have only transparency and black areas. So any overlay of the two will not show the black areas on the black part of the background. So I am reversing the black areas in the input images to white areas with transparency. Then the following command does the composition on all files using mogrify.

# On my desktop I created two folders, test1 and test2.
# I put 3 of your images into folder test1.
# test2 is going to be where the output images are placed.
# I put your background image on the desktop, not in either folder.
# I run the following to cd to test1 folder and then use mogrify to process all the files in test1 with the background image on the desktop

Code: Select all

cd desktop/test1
mogrify -path ../test2 -format png -alpha off -negate -alpha on -draw 'image DstOver 0,0 0,0 "../background.png"' *.GIF
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Append background to all images ?

Post by Rye »

Hmm... when I use your commands I get this:
C:\Users\Pascal\Desktop\close_z>append.bat

C:\Users\Pascal\Desktop\close_z>cd C:\Users\Pascal\Desktop\close_z

C:\Users\Pascal\Desktop\close_z>mogrify -path ../test2 -format png -alpha off -n
egate -alpha on -draw 'image DstOver 0,0 0,0 "../background.png"' *.GIF
mogrify.exe: unable to open image `DstOver': No such file or directory @ error/b
lob.c/OpenBlob/2641.
mogrify.exe: unable to open file `DstOver' @ error/png.c/ReadPNGImage/3759.
mogrify.exe: unable to open image `0,0': No such file or directory @ error/blob.
c/OpenBlob/2641.
mogrify.exe: unable to open file `0,0' @ error/png.c/ReadPNGImage/3759.
mogrify.exe: unable to open image `0,0': No such file or directory @ error/blob.
c/OpenBlob/2641.
mogrify.exe: unable to open file `0,0' @ error/png.c/ReadPNGImage/3759.
mogrify.exe: unable to open image `../background.png'': No such file or director
y @ error/blob.c/OpenBlob/2641.
mogrify.exe: unable to open module file `C:\Program Files\ImageMagick-6.8.3-Q16\
modules\coders\IM_MOD_RL_PNG'_.dll': No such file or directory @ warning/module.
c/GetMagickModulePath/683.
mogrify.exe: no decode delegate for this image format `../background.png'' @ err
or/constitute.c/ReadImage/550.
mogrify.exe: Non-conforming drawing primitive definition `image' @ error/draw.c/
DrawImage/3154.

C:\Users\Pascal\Desktop\close_z>
The image(s) created look like this
https://dl.dropboxusercontent.com/u/145 ... 00_096.png
https://dl.dropboxusercontent.com/u/145 ... 00_097.png
https://dl.dropboxusercontent.com/u/145 ... 00_089.png
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 background to all images ?

Post by fmw42 »

You have to use windows path syntax if running on Windows, I would expect. But I am not Window user, so this would need confirmation from one of the Windows users. see http://www.imagemagick.org/Usage/windows/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Append background to all images ?

Post by snibgo »

Without testing, I think this is a quoting issue. For Windows, swap the use of double/single quotes.
snibgo's IM pages: im.snibgo.com
Post Reply