from PIL import Imageimport osfrom concurrent.futures import ThreadPoolExecutor def add_watermark_to_image(filename, input_folder, watermark_path, output_folder): # 打开原始图片 img_path = os.path.join(input_folder,
import argparse class WatermarkText(): def __init__(self): parser = argparse.ArgumentParser(description='Add watermark to images.') parser.add_argument('--image_path', type=str, help='Path to the image directory.') parser.add_argument('--watermark_text', type=str, help='Text for waterm...
Next, we can write a Python script to add a watermark to an image. Let’s create a simple script that adds a text watermark to an image: fromPILimportImage,ImageDraw,ImageFontdefadd_watermark(input_image_path,output_image_path,watermark_text):# Open the input imageimage=Image.open(input_...
(img) def add_dct_watermark(image_path, output_path, watermark_text, alpha=0.1): try: image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE) watermark = text_to_image(watermark_text) block_size = 8 rows, cols = image.shape watermark = cv2.resize(watermark, (cols // block_size, rows...
``` # Python script to add watermarks to images from PIL import Image from PIL import ImageDraw from PIL import ImageFont def add_watermark(input_path, output_path, watermark_text): image = Image.open(input_path) draw = ImageDraw.Draw(image) font = ImageFont.truetype('arial.ttf', 36) ...
在add_watermark()方法中,我们将默认的fill参数设置为(255, 255, 255, 128),即白色半透明,这样可以让水印不会完全遮挡住原图。你可以根据需要修改该参数,例如将水印颜色修改为红色,可以将fill参数修改为(255, 0, 0, 128)。 textbbox参数解释 textbbox()方法是 Pillow 库中ImageDraw模块提供的一个函数,用于...
``` # Python script to add watermarks to images from PIL import Image from PIL import ImageDraw from PIL import ImageFont def add_watermark(input_path, output_path, watermark_text): image = Image.open(input_path) draw = ImageDraw.Draw(image) font = ImageFont.truetype('arial.ttf', 36) ...
PyDev console: starting.Python 3.6.13 |Anaconda, Inc.| (default, Mar 16 2021, 11:37:27) [MSC v.1916 64 bit (AMD64)] on win32runfile('D:/spyder/csdn/image_add_watermark_tool.py', wdir='D:/spyder/csdn')ffmpeg -i C:/Users/huyi/Desktop/1.jpg -vf drawtext=fontsize=100:fontfil...
我将程序分为了三个部分,通知处理模块Notify.py,图片处理模块Image.py,键盘监听模块Work.py AutoWatermark.exe Notify.py Image.py Work.py notify.py 具体功能 用于右下角的系统通知 Plyer Install theplyermodule withpip. python pip install plyer
watermark_x, watermark_y = tp.size# 水印位置 mask是通道值,240+ 是透明效果lp.paste(img, (image_x - watermark_x, image_y - watermark_y),mask = alpha)print('保存图片') lp.save('F:/lala.png',"PNG")if__name__ =='__main__': ...