我有一个JPEG:
我要插入PNG:
在JPEG上的128x128位置上。
做的时候
vips insert tile.jpg pin.png newimage.jpg 128 128
它给了我Error Output: insert: images must have the same number of bands, or one must be single-band
因为pin.jpg具有Alpha通道,而tile.jpg没有。
所以我将jpg转换为png:
convert tile.jpg png32:tile.png
现在我有了一个带有Alpha通道的tile.png:
但是当我现在打电话给:
vips insert tile.png pin.png newimage.png 128 128
我得到以下内容:
插入的pin.png的背景是白色。
我检查了vips insert --help-all
但没有真正找到有用的命令行参数。 这两个图像都有一个Alpha通道。 我的问题:
insert
命令是否支持透明背景?乐金
公民
你好@codecitizen ,
insert
是一个非常低级的操作:它只是将一个图像放在另一个图像上,它不进行任何混合。
在当前的libvips中,您需要将ifthenelse
与blend
选项一起使用。 这太可怕了:
# get the alpha channel from the overlay
vips extract_band marker.png alpha.png 3 --n 1
# get RGB from the overlay
vips extract_band marker.png rgb.png 0 --n 3
# find the size of the overlay
width=$(vipsheader -f width marker.png)
height=$(vipsheader -f height marker.png)
# cut out an area the size of marker from the background
vips extract_area background.jpg bg.png 128 128 $width $height
# blend the marker on top of the chunk of background
vips ifthenelse alpha.png rgb.png bg.png blended.png --blend
# insert the blended image back into the background
vips insert background.jpg blended.png final.jpg 128 128
要生成此:
libvips 8.6有一个新颖的composite
运算符,它可以执行所有常用的混合模式。 你可以做:
vips composite "background.jpg marker.png" final.jpg 2
2
表示over
混合模式。 它支持所有PDF混合模式。 应该在一周左右的时间内出来。
@jcupitt嘿,谢谢。 我安装了libvips 8.6, vips composite
工作得很好。 我只是不确定如何指定第二张图片的位置(如果可能)。
您可以放大叠加层以匹配大图像,然后进行构图:
width=$(vipsheader -f width background.jpg)
height=$(vipsheader -f height background.jpg)
vips embed marker.png overlay.png 128 128 $width $height
vips composite "background.jpg overlay.png" final.jpg 2
或切掉背景的一部分,进行构图,然后再插入(如上)。
这似乎是一件常见的事情,也许应该有一个选项来指定位置。
惊人的! 非常感谢您的快速帮助!
最有用的评论
您可以放大叠加层以匹配大图像,然后进行构图:
或切掉背景的一部分,进行构图,然后再插入(如上)。
这似乎是一件常见的事情,也许应该有一个选项来指定位置。