I have a transparent PNG file (a picture of a cow)

I have a folder that contains images of grass, mountains, rivers and so on.

I want to overlay the cow image onto those background images only by using Linux command line.


convert tool from the ImageMagick package

You can merge images using ImageMagick Layering


convert -page +0+0 grass.jpg \
    -page +256+0 clouds.jpg \
    -page +512+0 cow1.png \
    -background none -layers merge +repage merged.jpg

Batch convert several images

Let's suppose that you have two images: 1. grass.jpg as first image 2. and cow1.jpg, cow2.jpg etc as second image to merge

So, your bash script is:

for image in cow*.jpg; do
  convert -page +0+0 grass.jpg \
    -page +100+100 $image \
    -background none -layers merge +repage $image-merged.jpg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.