0

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 $_ ..}
Ooker
  • 1,969
  • 4
  • 28
  • 58
  • 1
    Remove `,@(...)`, it's forcing `ForEach-Object` to consume the whole inner array at once. `Get-ChildItem -Recurse -File | %{ magick $_.FullName ..\logo.png -composite output%d.png }` – Mathias R. Jessen Jan 13 '23 at 11:42
  • Thanks. If I use an increment variable then it works: `$i=0; gci -recurse -file | %{$i+=1;magick $_.fullname ..\logo.png -composite a$i.png}`. But using the input name directly then it doesn't: `gci -recurse -file | %{magick $_.fullname ..\logo.png -composite a$_.name}`. Do you know why? – Ooker Jan 13 '23 at 12:14
  • Parsing engine has two "modes" depending on whether it's parsing command arguments or value expressions. Change `a$_.name` to `"a$($_.name)"` – Mathias R. Jessen Jan 13 '23 at 12:16
  • Thanks, it works. Do you want to make that an answer? Also, where should I read more about it? – Ooker Jan 13 '23 at 12:18

2 Answers2

1

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

fmw42
  • 46,825
  • 10
  • 62
  • 80
0

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
} 
Ooker
  • 1,969
  • 4
  • 28
  • 58