【问题标题】:Generate background around an image with specific size [duplicate]在具有特定大小的图像周围生成背景[重复]
【发布时间】:2023-03-21 13:09:01
【问题描述】:

我有一个 N x N 像素的图像,我想用大小为 M x M 像素的白色背景包围它。我如何在 Python 中做到这一点?

【问题讨论】:

标签: python image image-processing


【解决方案1】:

如果您真的不想编写整个程序而只想在终端中输入一个简单的命令,您可以使用安装在大多数 Linux 发行版上并且适用于 OSX 和 Windows 的 ImageMagick。

命令是 - 假设 M 是 500:

convert input.png -background white -gravity center -extent 500x500 result.png

所以,如果您从这张 400x400 图像开始:

并运行它,使用蓝色,因为您可以在 StackOverflow 的白色背景上看到更好的效果:

convert input.png -background blue -gravity center -extent 500x500 result.png

你会得到这个

当然,如果你确实想写一个 Python 程序,请忽略我 :-)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-27
    • 1970-01-01
    • 1970-01-01
    • 2015-11-28
    • 2016-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多