我试图将png图像作为水印添加到现有的pdf中,我尝试使用PyMuPDF的“ Page.Insertimage”,尽管我成功地将图像插入为水印,但是水印却以灰度显示。我已经尝试了2种不同的png,但结果始终是灰度的。请帮助我在哪里错了?
图像(水印温度)旋转了45度,其alpha值为15%,即38。
im2= Image.open(watermarktemp).convert('RGBA')
file_handle = fitz.open(inputfile)
nop=file_handle.pageCount
widthim, heightim = im2.size
pix = fitz.Pixmap(watermarktemp)
# retrieve the number of pages and loop over it
for pgno in range(nop):
page = file_handle[pgno]
width=page.bound()[2]
height=page.bound()[3]
#creating rectangle at centre of page
srtx=(width-widthim)/2
srty=(height-heightim)/2
stpx=(width+widthim)/2
stpy=(height+heightim)/2
rect = fitz.Rect(srtx,srty,stpx,stpy)
# add the image
page.insertImage(rect, pixmap = pix, overlay = True)
file_handle.save(outputfile)
预期结果:带有彩色水印的PDF 实际结果:带有灰度水印的PDF