ImageMagick 无需插值调整大小

ImageMagick resize without interpolation

我有一张小像素图 ,想调整它的大小以提高可读性。

使用 mogrify -resize 1600% 我得到一个插值图像:

我想要得到的是:

这可以通过 ImageMagick 或任何其他开源命令行工具完成吗?

我终于找到了解决方案:使用 -scale 而不是 -resize 就可以了。它是 Scale - Minify with pixel averaging 标题下的 'hidden',因此我一开始忽略了它,搜索 magnification 而不是 minification

这对我有用:

convert input.png -interpolate Integer -filter point -resize "10000%" output.png

说明:

  • 插值方法"Integer"只是选择一个最接近的值。
  • 过滤器'point'也是必须的,但我不知道为什么。

要保持​​输入图像的原始值并避免任何混合或模糊,您可以使用 -interpolate nearest-neighbor-interpolate integer

它只适用于 -interpolative-resize。请注意 -resize 不能与 -interpolate 一起正常工作。您可以在 imagemagick 文档上查看 here

例如

convert input.png -interpolate nearest-neighbor -interpolative-resize 1600% output.png

display -sample 400% 对我有用。

"通过直接从图像原始像素采样来改变图像大小。放大时,像素以块为单位复制。缩小时,像素为 sub-sampled(即跳过某些行和列)."

https://imagemagick.org/script/command-line-options.php#sample