使用 imagemagick 将边框添加到图像顶部
我有一个 100x40 的图像,我想在图像顶部添加一个 10 像素高的边框。
我发现
convert source.jpg -border 0x10 out.jpg
但这会在顶部和底部添加边框。有没有办法只将其添加到顶部?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
-splice
:convert source.jpg -splice 0x10 out.jpg
如果您只想在底部添加边框,请使用
-重力
以及:convert source.jpg -gravity South -splice 0x10 out.jpg
请注意,边框将是透明的,除非您也使用
-background
。另请参阅剪切和边框了解更多示例。
Use
-splice
:convert source.jpg -splice 0x10 out.jpg
If you want to add the border only at the bottom, use
-gravity
as well:convert source.jpg -gravity south -splice 0x10 out.jpg
Note that the border will be transparent, unless you use
-background
, too.See also Cutting and Bordering for more examples.
使用
-extent
代替:-gravity
告诉它向哪个方向移动原始图像。Use
-extent
instead:-gravity
tell it which direction to move the original image.自 2011 年 9 月 6 日起进行测试,默认背景现在为白色,不透明,至少对于 PNG 输入/输出而言是如此。
要获得透明背景,您需要类似:
north
添加到顶部,south
添加到底部。另请注意,
-background
必须位于-splice
之前。演示 JPG 输入:
未修改的输入预览:
顶部有 100 像素白色边框,
-重力北
(白色是默认颜色):顶部有 100 像素黑色边框
-背景黑色
:底部有黑色边框,
-重力南
:顶部和底部均带有黑色边框双
-gravity
+-splice
:图像周围有 100 像素黑色边框,而不是按照 -border href="https://askubuntu.com/questions/819482/how-to-add-a-border-using-imagemagick">https://askubuntu.com/questions/819482/how-to-add-a- border-using-imagemagick
Tested as of 6.9.11, the default background is now white, not transparent, at least for PNG input/output.
To get a transparent background you need something like:
north
adds on top,south
on bottom.Also note that
-background
has to come before-splice
.Demo JPG input:
Unmodified input preview:
100 px white border on top with
-gravity north
(white is the default color):100 px black border on top with
-background black
:Black border on bottom with
-gravity south
:Black border on both top and bottom with a double
-gravity
+-splice
:100px black border all around image instead with
-border
as per https://askubuntu.com/questions/819482/how-to-add-a-border-using-imagemagick