Imagemagick 内联边框不调整原始图像的大小

Imagemagick inline border without resizing the original image

我尝试使用以下代码为尺寸为 200x200 像素的图像添加边框。

convert -border 2x2 -bordercolor "#cccccc" old.png new.png

以上代码在 old.png 周围添加了一个 2 像素的边框。因此,图像扩展为 204x204 像素。

但是,我想添加一个 inline 边框。我对旧图像的边框 覆盖 边缘部分没有任何问题。因此,新图像应该能够保留 200x200 像素的尺寸。请告知具体如何操作。

您需要将周围的两个像素剃掉,然后添加两个像素的边框。您应该使用 Imagemagick 6 尝试此操作。如果使用 Imagemagick 7,请将 convert 替换为 magick。

convert old.png -shave 2x2 -bordercolor "#cccccc" -border 2 new.png