overlay 2 images and keep the same name

huangapple go评论58阅读模式
英文:

imagemagick overlay 2 images and keep the same name

问题

I'm using magick to add png images to a t-shirt, and the images are saved as result01, result02, etc..
I was wondering if i could save the images with the names of the pngs from the folder "overlays"
This is the code i'm using at the moment:

magick main.jpg -colorspace sRGB -gravity center null: ( ..\Pictures\overlays*.png -resize 600x600 ) -geometry -10-30 -compose over -layers composite result%04d.png

I have also tried this, but it gives the name of the main image, not the overlay pngs:

magick main.jpg -colorspace sRGB -gravity center null: ( ..\Pictures\overlays*.png -resize 600x600 ) -geometry -10-80 -compose over -layers composite -set filename:f "%t_%p" %[filename:f].png

Thanks to everyone in advance

英文:

I'm using magick to add png images to a t-shirt, and the images are saved as result01, result02, etc..
I was wondering if i could save the images with the names of the pngs from the folder "overlays"
This is the code i'm using at the moment:

magick main.jpg -colorspace sRGB -gravity center null: ( ..\Pictures\overlays\*.png -resize 600x600 ) -geometry -10-30 -compose over -layers composite result%04d.png

I have also tried this, but it gives the name of the main image, not the overlay pngs: 

magick main.jpg -colorspace sRGB -gravity center null: ( ..\Pictures\overlays\*.png -resize 600x600 ) -geometry -10-80 -compose over -layers composite -set filename:f "%t_%p" %[filename:f].png

Thanks to everyone in advance

答案1

得分: 2

ImageMagick似乎保留了底层的输入文件名,作为合成的目标图像。以下是一种将叠加图像用作目标图像的方法,因此这些文件名将被用作“filename:0”变量,并仍然将这些叠加图像合成到主图像的顶部。

(注意:该命令使用Windows CMD格式。对于BAT脚本,您需要将所有百分号“%”加倍“%%”。)

magick main.jpg -colorspace sRGB -background none -gravity center ^
   null: ( ..\Pictures\overlays\*.png -resize 600x600 ) ^
   -extent %[fx:u.w]x%[fx:u.h]-%[fx:t?10:0]-%[fx:t?80:0] ^
   -set filename:0 "%[t]_%

" -reverse -compose dstover ^ -layers composite %[filename:0].png

这会读取主图像并设置颜色空间、重力和背景颜色。然后,它添加了所需的“null:”图像以用于“-layers composite”。括号内部它会读取所有的叠加图像并根据需要调整大小。

接下来,它使用“-extent”操作将主图像保留为其原始尺寸,并在所有叠加图像上添加一个具有主图像尺寸的透明背景画布,并使用您的“-10-80”几何定位叠加图像。

然后设置所有的“filename:0”变量,并将图像顺序“-reverse”。这将安排叠加图像作为目标图像。

使用“dstover”合成方法时,目标图像,也就是这些叠加图像,将与主图像叠加在一起,同时在输出图像文件名中使用每个叠加图像的文件名。

英文:

ImageMagick seems to hold the input file name of the bottom layer, the destination image of a composite. Here is one way to use the overlay images as the destination image, so those file names will be used as the "filename:0" variable, and still composite those overlays on top of the main image.

(Note: The command is in Windows CMD format. For a BAT script you'd need to double all the percent signs "%%".)

magick main.jpg -colorspace sRGB -background none -gravity center ^
   null: ( ..\Pictures\overlays\*.png -resize 600x600 ) ^
   -extent %[fx:u.w]x%[fx:u.h]-%[fx:t?10:0]-%[fx:t?80:0] ^
   -set filename:0 "%[t]_%

" -reverse -compose dstover ^ -layers composite %[filename:0].png

That reads in the main image and sets the colorspace, gravity, and background color. Then it adds the required "null:" image for the "-layers composite". Inside the parentheses it reads in all the overlay images and resizes them as needed.

Next it uses an "-extent" operation that leaves the main image its original dimensions, and adds a transparent background canvas with the main image's dimensions to all the overlays, and locates the overlays with your "-10-80" geometry.

Then set all the "filename:0" variables, and "-reverse" the order of the images. That will arrange the overlays as the destination images.

Using the compose method of "dstover", the destination images, those overlays, will be composited on top of the main image, while using each overlay image's file name in the output image file name.

huangapple
  • 本文由 发表于 2023年6月26日 06:31:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76552653.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定