如何解决ImageMagick 脚本因误导文件名或扩展名太长而失败 (-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 ...
编辑:调整
- 将
magick convert
替换为magick
- 将
$fuzz = 50
替换为$fuzz = "50%"
- 将
$size = 50
替换为$size = 100
编辑 2:
内部魔法命令(magick convert $out sparse-color:
)的结果如下所示:
# ImageMagick pixel enumeration: 100,100,255,srgba
0,0: (87,72,86,0) #57485600 srgba(87,0)
1,0: (105,81,91,0) #69515B00 srgba(105,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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。