ImageMagick - 为许多照片添加白色边框,其尺寸相对于宽度和高度(例如:宽度 * 1.34%)

发布于 2025-01-17 23:09:13 字数 361 浏览 1 评论 0原文

是否可以编写一个脚本,可以创建文件中所有图片的副本,并为其添加白色边框,边框乘以一定的百分比?

我希望新图像(旧图像+边框)的宽度约为旧图像的 134%,高度约为旧图像的 165%。

我想这相当简单,但并不积极,到目前为止我的所有尝试都没有成功。

到目前为止,我当前的代码是:

'''for i in ls; do name = "mat_$i" echo "正在处理 $name..." ;转换 $i -bordercolor 白色 -border 1x2 $name;完成''''

1x2 肯定是关闭的,但我在那里尝试过的任何方法都不起作用。

我还想添加元数据,因为其中一些图片是专业的,并且可能在线分发。提前致谢。

Is it possible to write a script that can create a copy of all the pictures in a file and add a white border to it with the border multiplied by a certain percentage?

I want the width of the new image (old image + border) to be about 134% of the old one and height about 165% of the old one.

I imagine this is fairly simple but not positive how and all my attempts so far have been unsuccessful.

My current code so far is:

'''for i in ls; do name = "mat_$i" echo "processing $name..." ; convert $i -bordercolor white -border 1x2 $name; done''''

The 1x2 is off for sure, but nothing I have tried there worked either.

I would also like to add meta data as some of these pics are professional and maybe distributed online. Thanks in advance.

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

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

发布评论

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

评论(1

拧巴小姐 2025-01-24 23:09:13

这是 Imagemagick 6 的一种方法。

输入:

在此处输入图像描述

infile="barn.jpg"
bgcolor="red"
inname=`convert "$infile" -format "%t" info:`
declare `convert "$infile" -format "ww=%[fx:w*134/100]\nhh=%[fx:h*165/100]" info:`
convert -size ${ww}x${hh} xc:"$bgcolor" "$infile" -gravity center -composite "${inname}_pad.jpg"

结果:

在此处输入图像描述

对于 Imagemagick 7,您可以按如下方式内联执行此操作:

magick barn.jpg -size "%[fx:w*134/100]x%[fx:h*165/100]" xc:red +swap -gravity center -composite barn_pad.jpg

Here is one way for Imagemagick 6.

Input:

enter image description here

infile="barn.jpg"
bgcolor="red"
inname=`convert "$infile" -format "%t" info:`
declare `convert "$infile" -format "ww=%[fx:w*134/100]\nhh=%[fx:h*165/100]" info:`
convert -size ${ww}x${hh} xc:"$bgcolor" "$infile" -gravity center -composite "${inname}_pad.jpg"

Result:

enter image description here

For Imagemagick 7, you can do that inline as follows:

magick barn.jpg -size "%[fx:w*134/100]x%[fx:h*165/100]" xc:red +swap -gravity center -composite barn_pad.jpg
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文