Home > Mobile >  How to overlay a logo to many images at once?
How to overlay a logo to many images at once?

Time:01-14

To overlay a logo in an image, I can use:

magick background.jpg logo.jpg -composite output.jpg

However, I don't know how to use this in batch. From What's the equivalent of xargs in PowerShell?, my try is:

,@(gci -recurse -file) | %{magick $_ ..\logo.png -composite output%d.png} 

But it only produce one output output0.png which seems to be a -composite of all the images in the folder, not a list of new outputs which combine each image in the folder with the logo image.

This still works:

,@(gci -recurse -file) | %{Copy-Item $_ ..}

CodePudding user response:

My current working script:

gci -recurse -file | Foreach-Object {
    $out="new" $_.name
    "Input = "   $_.name   "`nOutput = "   $out
    rm $out
    $bgWidth = $(magick identify -format %w $_.name) -as [float] 
    $bgHeight = $(magick  identify -format %h $_.name) -as [float]
    $logoWidth = $bgWidth*0.05 -as [float] 
    $logoHeight = $bgHeight*0.05 -as [float] 
    
    magick "..\Logo\logo1.png" -resize x$logoHeight logo1_resized.png
    magick "..\Logo\logo2.png" -resize x$logoHeight logo2_resized.png
    magick convert logo1_resized.png logo2_resized.png  append logo_stacked.png

    $logoOffset = $bgWidth*0.01
    
    magick $_ logo_stacked.png -gravity northeast -geometry  $logoOffset $logoOffset -composite $out
} 

CodePudding user response:

You can use magick mogrify in Imagemagick to overlay a logo on many jpg images. Just keep the logo in a different directory if it is JPG also in this case so it is not tried to be put on itself. If it is PNG or some other format, then it can be in the same directory. First, cd to the directory holding your images. Then

magick mogrify -format jpg -draw 'image over 0,0 0,0 "path_to/logo.jpg"' *.jpg

See https://imagemagick.org/Usage/basics/#mogrify and https://imagemagick.org/Usage/basics/#mogrify_compose

  • Related