Python - 图片水印
Python - image watermark
我的目标是基于徽标(TIF 格式)和背景图像 (JPG) 创建水印图像。
我正在使用此代码:
from PIL import Image
def watermark_with_transparency(input_image_path,
output_image_path,
watermark_image_path,
position):
base_image = Image.open(input_image_path)
watermark = Image.open(watermark_image_path)
width, height = base_image.size
transparent = Image.new('RGBA', (width, height), (0,0,0,0))
transparent.paste(base_image, (0,0))
transparent.paste(watermark, position, mask=watermark)
transparent.show()
transparent.save(output_image_path)
水印图像是透明的 TIF。
如果我运行上面的代码,水印结果不包含任何标识。
我做错了什么?
from PIL import Image,ImageDraw, ImageFont
path=r'/home/anuj/FIle_server/production/AI_PROJECT/SEQ_001/sq1/frm_seq_v001.001.jpeg' #This is path of your image
demo_image = Image.open(path)
img_width, img_height =demo_image.size
draw_image = ImageDraw.Draw(demo_image)
text_image ="HQVFX" #Here you can assign your watermark.
font_image =ImageFont.truetype('/home/anuj/FIle_server/task/WaterBrush-Regular.ttf',50)
text_width, text_height = draw_image.textsize(text_image,font_image)
font_margin = 10
x = img_width - text_width - font_margin
y = img_height - text_height - font_margin
draw_image.text((x,y), text_image, font= font_image)
demo_image.show()
demo_image.save("watermark.jpg")
我的目标是基于徽标(TIF 格式)和背景图像 (JPG) 创建水印图像。 我正在使用此代码:
from PIL import Image
def watermark_with_transparency(input_image_path,
output_image_path,
watermark_image_path,
position):
base_image = Image.open(input_image_path)
watermark = Image.open(watermark_image_path)
width, height = base_image.size
transparent = Image.new('RGBA', (width, height), (0,0,0,0))
transparent.paste(base_image, (0,0))
transparent.paste(watermark, position, mask=watermark)
transparent.show()
transparent.save(output_image_path)
水印图像是透明的 TIF。 如果我运行上面的代码,水印结果不包含任何标识。
我做错了什么?
from PIL import Image,ImageDraw, ImageFont
path=r'/home/anuj/FIle_server/production/AI_PROJECT/SEQ_001/sq1/frm_seq_v001.001.jpeg' #This is path of your image
demo_image = Image.open(path)
img_width, img_height =demo_image.size
draw_image = ImageDraw.Draw(demo_image)
text_image ="HQVFX" #Here you can assign your watermark.
font_image =ImageFont.truetype('/home/anuj/FIle_server/task/WaterBrush-Regular.ttf',50)
text_width, text_height = draw_image.textsize(text_image,font_image)
font_margin = 10
x = img_width - text_width - font_margin
y = img_height - text_height - font_margin
draw_image.text((x,y), text_image, font= font_image)
demo_image.show()
demo_image.save("watermark.jpg")