如何使用 Imagemagick 添加边框

Den*_*niz 10 imagemagick image-processing

我想在 Imagemagick 中添加到我的图片中:

  • 白色边框
  • 2英寸宽

我该怎么做?

小智 12

convert -bordercolor white -border 20 input.jpg output.jpg
Run Code Online (Sandbox Code Playgroud)

将向图像添加大小为 20 像素的白色边框。您只需要找出图像的一英寸 (dpi) 是多少像素。

可以在此处找到更多示例。

如果是我的测试图像,它已在其中保存了 dpi 信息。我可以使用它identivy -verbose,它看起来像这样:

$ identify -verbose tiger.jpg
Image: tiger.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Mime type: image/jpeg
  Class: DirectClass
  Geometry: 600x400+0+0
  Resolution: 96x96
  Print size: 6.25x4.16667
  Units: PixelsPerInch
  Type: TrueColor
...
Run Code Online (Sandbox Code Playgroud)

如您所见,它具有 96x96 dpi,因为单位类型为 PixelsPerInch。

在这种情况下,我的图像上的 2 英寸是 192 像素。