0

I basically want to take a line of text and output it as a .png file. This snippet here on its own works fine:

convert -background lightblue -fill blue -font Candice -pointsize 72 label:Anthony test.png

I have about 100 lines I need to process though, So I tried to do it through a loop, using PowerShell:

 $MGLTriggers = Get-Content -Path ".\MGl\MG_Config.txt" -TotalCount 100
 foreach ($CurItem in $MGLTriggers){
    $Path = Join-Path -Path "./mgl/" -ChildPath ($CurItem + ".png")
    convert -background lightblue -fill blue -font Candice -pointsize 72 label:$CurItem         $Path}

Convert.exe throws this error for all the items:

convert.exe: no encode delegate for this image format `LABEL' @ error/constitute.c/WriteImage/1272.

I’ve searched everywhere and pulled fair amount of hair. What am I doing wrong? Any help would be appreciated.

Netmano93
  • 75
  • 1
  • 7

1 Answers1

1

The following snippet runs on my environment without errors:

$ItemList = @(
    'John Lennon',
    'George Harrison',
    'Paul McCartney',
    'Ringo Starr'
) 

foreach ($Item in $ItemList) {
    $Path = Join-Path -Path 'D:\sample\empty' -ChildPath ($Item + '.png')
    & "C:\Program Files\ImageMagick-7.1.0-Q16-HDRI\convert.exe" -background "lightblue" -fill "blue" -font "consolas" -pointsize 72 label:"$Item" $Path
}

BTW: When you crosspost the same question at the same time to different forums you should at least post links to the other forums along with your question to avoid people willing to help you making their work twice or more.

Thanks in advance ;-)

PowerShell.org Forum - ImageMagick throws error when used with PowerShell

mklement0
  • 382,024
  • 64
  • 607
  • 775
Olaf
  • 4,690
  • 2
  • 15
  • 23
  • I'm glad your answer solved the OP's problem, but it's not immediately obvious what made the difference. Can you please point that out in your answer? – mklement0 Jul 31 '21 at 22:55
  • As an aside: `label:"$Item"` may create the mistaken impression that`$item` must be double-quoted, which isn't true - `label:$Item` is sufficient. In general, it's worth avoiding arguments composed of unquoted and quoted parts, because the results [situationally vary](https://stackoverflow.com/a/65380907/45375). – mklement0 Jul 31 '21 at 23:05