使用 imagemagick 将边框添加到图像顶部

发布于 2024-08-22 16:37:37 字数 160 浏览 2 评论 0 原文

我有一个 100x40 的图像,我想在图像顶部添加一个 10 像素高的边框。

我发现

convert source.jpg -border 0x10 out.jpg

但这会在顶部和底部添加边框。有没有办法只将其添加到顶部?

I have an image 100x40 and I want to add a border to the top of the image 10 pixels high.

I've found

convert source.jpg -border 0x10 out.jpg

but this adds a border to the top and bottom. Is there anyway to add it to only the top?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

人│生佛魔见 2024-08-29 16:37:37

使用-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.

星光不落少年眉 2024-08-29 16:37:37

使用 -extent 代替:

convert source.jpg -gravity south -extent 100x50 out.jpg

-gravity 告诉它向哪个方向移动原始图像。

Use -extent instead:

convert source.jpg -gravity south -extent 100x50 out.jpg

-gravity tell it which direction to move the original image.

莫言歌 2024-08-29 16:37:37

自 2011 年 9 月 6 日起进行测试,默认背景现在为白色,不透明,至少对于 PNG 输入/输出而言是如此。

要获得透明背景,您需要类似:

convert source.png -gravity north -background transparent -splice 0x10 out.png

north 添加到顶部,south 添加到底部。

另请注意,-background 必须位于-splice 之前。

演示 JPG 输入:

wget -O chick.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Hühnerküken_02.jpg/800px-Hühnerküken_02.jpg

未修改的输入预览:

输入图片此处描述

顶部有 100 像素白色边框,-重力北(白色是默认颜色):

convert chick.jpg -gravity north -splice 0x100 chick-default.jpg

在此处输入图像描述

顶部有 100 像素黑色边框 -背景黑色

convert chick.jpg -gravity north -background black -splice 0x100 chick-black.jpg

在此处输入图像描述

底部有黑色边框,-重力南

convert chick.jpg -gravity south -background black -splice 0x100 chick-black-south.jpg

在此处输入图像描述

顶部和底部均带有黑色边框双-gravity + -splice

convert chick.jpg -background black -gravity south -splice 0x100 \
  -gravity north -splice 0x100 chick-black-north-south.jpg

在此处输入图像描述

图像周围有 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

convert -bordercolor black -border 100 chick.jpg chick-around.jpg

在此处输入图像描述

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:

convert source.png -gravity north -background transparent -splice 0x10 out.png

north adds on top, south on bottom.

Also note that -background has to come before -splice.

Demo JPG input:

wget -O chick.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Hühnerküken_02.jpg/800px-Hühnerküken_02.jpg

Unmodified input preview:

enter image description here

100 px white border on top with -gravity north (white is the default color):

convert chick.jpg -gravity north -splice 0x100 chick-default.jpg

enter image description here

100 px black border on top with -background black:

convert chick.jpg -gravity north -background black -splice 0x100 chick-black.jpg

enter image description here

Black border on bottom with -gravity south:

convert chick.jpg -gravity south -background black -splice 0x100 chick-black-south.jpg

enter image description here

Black border on both top and bottom with a double -gravity + -splice:

convert chick.jpg -background black -gravity south -splice 0x100 \
  -gravity north -splice 0x100 chick-black-north-south.jpg

enter image description here

100px black border all around image instead with -border as per https://askubuntu.com/questions/819482/how-to-add-a-border-using-imagemagick

convert -bordercolor black -border 100 chick.jpg chick-around.jpg

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文