ImageMagick 脚本因误导文件名或扩展名太长而失败(-sparse-color)

ImageMagick script fails with MISLEADING filename or extension too long (-sparse-color)

问题

在我很短的脚本中,我遇到了一个问题,它有时会报告文件名或扩展名太长。根据脚本中的 $image$size 值,此错误可能会发生也可能不会发生。

例如下面的脚本使用来自 here 的图像产生此错误 - 保存并转换为“example3.png”。

我确实在 windows 上使用版本:ImageMagick 7.0.10-62 Q16 x64,但我不知道如何处理错误消息...知道这里的问题是什么吗?

Powershell 脚本

#####################
# Setup
#####################

$image = "./example3.png"
$out = "./result.png"
$outPalette = "./palette.png"

$size = 50
$fuzz = 50
$colors = 6
$resizedSize = "$($size)x$($size)`!"
$histogramSize = "$($size)x$($size)"

#####################
# Program
#####################

Write-Host ""

# 1) Scale + change depth + remove unwanted colors (b/w)
Write-Host "- Step 1..." -ForegroundColor Green
magick convert $image -scale $resizedSize -depth 8 `
    -fuzz $fuzz -transparent black -transparent white `
    $out

#2) create histogram with the help of the sparse colors
Write-Host "- Step 2..." -ForegroundColor Green
$dataHistogram = magick convert -size $histogramSize xc: -sparse-color voronoi ( magick convert $out sparse-color: ) +dither -colors $colors -depth 8 -format %c histogram:info:

# ... more ...

编辑:调整

现在可以使用更多图像,但例如以下仍然失败并出现相同的错误:

编辑2:

内部 magick 命令 (magick convert $out sparse-color:) 的结果如下所示:

# ImageMagick pixel enumeration: 100,100,255,srgba
0,0: (87,72,86,0)  #57485600  srgba(87,72,86,0)
1,0: (105,81,91,0)  #69515B00  srgba(105,81,91,0)
...

我不确定 powershell 发生了什么,但如果问题是命令行的长度,您可以从这样的文件中提供稀疏颜色:

magick -size 800x600 xc: -sparse-color voronoi @colors.txt result.png

或者在 stdin 上这样:

echo "10,10 red 200,200 yellow" | magick -size 800x600 xc: -sparse-color voronoi @- result.png