最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于Python實現(xiàn)圖片批量加水印的方法

 更新時間:2025年11月17日 09:47:08   作者:愛分享的飄哥  
我們經(jīng)常有有這樣的經(jīng)歷:辛辛苦苦制作的原創(chuàng)圖片、精心拍攝的作品、耗費心血設計的宣傳圖,剛發(fā)布到網(wǎng)上,沒過多久,就發(fā)現(xiàn)被別人盜用維 權(quán)耗時耗力,讓人沮喪,今天,我們將深入Python圖片處理的世界,手把手教你如何基于Python實現(xiàn)圖片批量加水印,需要的朋友可以參考下

原創(chuàng)作品被盜用?是時候給你的圖片加個“專屬烙印”了!

我們經(jīng)常有有這樣的經(jīng)歷?

辛辛苦苦制作的原創(chuàng)圖片、精心拍攝的作品、耗費心血設計的宣傳圖……剛發(fā)布到網(wǎng)上,沒過多久,就發(fā)現(xiàn)被別人盜用維 權(quán)耗時耗力,讓人沮喪。

除了版權(quán)保護,你可能還希望:

為公司所有宣傳圖加上統(tǒng)一的品牌Logo,提升專業(yè)度。

為教育課件或資料圖加上“僅供學習使用”的文字水印。

為批量生成的二維碼圖加上你的公眾號名稱。

面對成百上千張圖片,手動打開Photoshop或在線工具,一張張?zhí)砑铀?,調(diào)整位置、透明度……這簡直是效率的噩夢!你甚至會因此放棄給圖片加水印,從而讓你的作品面臨被盜用的風險。

是時候讓Python出馬,為你徹底解決這些煩惱了!今天,我們將深入Python圖片處理的世界,手把手教你如何打造一套Python圖片自動化的終極指南,讓你輕松實現(xiàn):

  • Python批量添加文字水?。?自定義字體、顏色、大小、透明度,讓你的版權(quán)聲明清晰可見。
  • Python批量添加圖片水?。?輕松疊加Logo、二維碼,提升品牌辨識度。
  • 一鍵式批量加水?。?告別手動操作,高效保護你的每一張作品!

準備好了嗎?讓我們一起告別手動P圖,開啟高效的圖片版權(quán)保護新篇章!

1. 圖片水印核心利器:Python Pillow庫與ImageDraw

要實現(xiàn)Python圖片加水印,我們依然需要用到強大的Pillow庫。而Pillow中的一個重要模塊——ImageDraw,正是實現(xiàn)文字和圖形繪制的關(guān)鍵。

Pillow的ImageDraw模塊允許你在圖片上“畫畫”和“寫字”。我們可以利用它在圖片上繪制文字或粘貼另一張圖片(Logo),從而實現(xiàn)水印功能。

依然首先需要安裝pillow

pip install Pillow

1.1 給圖片加上你的“名字”——文字水印

from PIL import Image, ImageDraw, ImageFont # 導入Image, ImageDraw, ImageFont模塊
import os

def add_text_watermark_basic(image_path, text="您的版權(quán)聲明", output_folder="watermarked_images"):
    """
    給單張圖片添加文字水印,這是Python圖片加水印的基礎。
    :param image_path: 源圖片文件路徑
    :param text: 要添加的水印文字
    :param output_folder: 輸出文件夾
    """
    if not os.path.exists(image_path):
        print(f"? 圖片文件不存在:{image_path}")
        return

    os.makedirs(output_folder, exist_ok=True) # 確保輸出文件夾存在

    try:
        img = Image.open(image_path).convert("RGBA") # 轉(zhuǎn)換為RGBA模式,支持透明度
        draw = ImageDraw.Draw(img) # 創(chuàng)建一個繪圖對象

        # 設置字體和大小 (請根據(jù)你的系統(tǒng)和需求調(diào)整字體文件路徑)
        # 例如 Windows: "C:/Windows/Fonts/simhei.ttf" (黑體) 或 "arial.ttf"
        try:
            font = ImageFont.truetype("C:/Windows/Fonts/simhei.ttf", 40) # 使用黑體支持中文
        except IOError:
            print("字體文件未找到,將使用默認字體。")
            font = ImageFont.load_default() # 如果找不到,加載默認字體

        # 設置水印位置(右下角)
        bbox = draw.textbbox((0, 0), text, font=font)  # 獲取文字邊界
        text_width = bbox[2] - bbox[0]
        text_height = bbox[3] - bbox[1]
        # 計算文字繪制位置,距離右下角20像素
        x = img.width - text_width - 20
        y = img.height - text_height - 20

        # 設置文字顏色和透明度 (R, G, B, Alpha)
        # 這里創(chuàng)建一個半透明的灰色文字 (128是透明度,0-255)
        text_color = (128, 128, 128, 128) 

        # 繪制文字
        draw.text((x, y), text, font=font, fill=text_color)

        # 保存圖片
        output_path = os.path.join(output_folder, "watermarked_" + os.path.basename(image_path))
        # 保存為PNG以保留透明度,如果保存為JPG,透明度會變成白色背景
        img.save(output_path) 
        print(f"? 圖片已添加文字水印并保存到:{output_path}")

        img.close()
    except Exception as e:
        print(f"? 處理圖片失?。簕e}")

if __name__ == "__main__":
    # 請?zhí)鎿Q為你的實際圖片路徑
    test_image_path = os.path.expanduser("D:\\lx\\fengjing.png") 
    output_dir = os.path.expanduser("D:\\lx\\watermarked_images")

    # 確保有測試圖片
    if not os.path.exists(test_image_path):
        print(f"請在 '{os.path.dirname(test_image_path)}' 放置一個名為 'my_original_photo.jpg' 的圖片文件進行測試。")
    else:
        add_text_watermark_basic(test_image_path, text="愛分享的飄哥", output_folder=output_dir)

操作步驟:

準備圖片: 在所在路徑下,比如我是在D:\lx 下面準備一張

修改代碼路徑和水印文字: 復制上方代碼到VS Code,保存為ImageWater.py。修改 test_image_path、output_dir 和 text。

運行: 在VS Code終端運行 python add_watermark_basic.py。

效果展示:

最終結(jié)果:

2. Python批量加水印:你的圖片版權(quán)保護神器!

現(xiàn)在,你已經(jīng)掌握了單張圖片加水印的方法。但是,如果圖片有上百張,甚至上千張呢?當然是Python批量加水??!我們將把這個功能自動化,實現(xiàn)一鍵添加版權(quán)或Logo,成為你專屬的圖片版權(quán)保護神器。

封裝水印邏輯,遍歷文件夾下的所有圖片,并應用水印。我們將實現(xiàn)兩種最常用的批量加水印方式:文字水印和圖片Logo水印。

2.1 批量添加文字水?。鹤煮w、顏色、透明度、位置隨心定!

你需要為一系列發(fā)布到社交媒體或網(wǎng)站的圖片統(tǒng)一添加公司名稱、版權(quán)年份或個人簽名,并要求水印樣式一致。

編寫一個通用的函數(shù),可以批量處理文件夾中的圖片,并為每張圖片添加自定義樣式的文字水印。

from PIL import Image, ImageDraw, ImageFont
import os

def add_text_watermark_batch(source_folder, output_folder, watermark_text,
                             font_path="arial.ttf", font_size=40,
                             text_color=(0, 0, 0, 128), position="bottom_right"):
    """
    批量給指定文件夾下的圖片添加文字水印。
    這是高效的Python批量添加文字水印腳本。
    :param source_folder: 源圖片文件夾路徑
    :param output_folder: 輸出文件夾路徑
    :param watermark_text: 要添加的水印文字
    :param font_path: 字體文件路徑 (如 "arial.ttf", "simhei.ttf")
    :param font_size: 字體大小
    :param text_color: 文本顏色 (R, G, B, Alpha),Alpha為透明度 (0-255)
    :param position: 水印位置 ("top_left", "top_right", "bottom_left", "bottom_right", "center")
    """
    if not os.path.exists(source_folder):
        print(f"? 源文件夾不存在:{source_folder}")
        return

    os.makedirs(output_folder, exist_ok=True)
    files = [f for f in os.listdir(source_folder) if os.path.isfile(os.path.join(source_folder, f))]

    # 嘗試加載字體
    try:
        font = ImageFont.truetype(font_path, font_size)
    except IOError:
        print(f"?? 字體文件 '{font_path}' 未找到,使用默認字體。")
        font = ImageFont.load_default()

    print(f"?? 正在批量為 '{source_folder}' 下的圖片添加文字水印...")
    for filename in files:
        source_path = os.path.join(source_folder, filename)
        output_path = os.path.join(output_folder, "watermarked_" + filename)
        
        try:
            img = Image.open(source_path).convert("RGBA") # 轉(zhuǎn)換為RGBA支持透明度
            draw = ImageDraw.Draw(img)

            # 獲取文字尺寸 (注意:textsize在Pillow 10.0后廢棄,推薦textbbox)
            # 使用textbbox替代textsize for Pillow 10+
            bbox = draw.textbbox((0, 0), watermark_text, font=font)
            text_width = bbox[2] - bbox[0]
            text_height = bbox[3] - bbox[1]

            # 根據(jù)位置計算水印坐標
            if position == "top_left":
                x, y = 10, 10
            elif position == "top_right":
                x, y = img.width - text_width - 10, 10
            elif position == "bottom_left":
                x, y = 10, img.height - text_height - 10
            elif position == "bottom_right":
                x, y = img.width - text_width - 10, img.height - text_height - 10
            elif position == "center":
                x, y = (img.width - text_width) / 2, (img.height - text_height) / 2
            else:
                x, y = img.width - text_width - 10, img.height - text_height - 10 # 默認右下角

            draw.text((x, y), watermark_text, font=font, fill=text_color)
            
            # 保存圖片,如果原始是PNG,可以嘗試保存回PNG以保留透明度,否則轉(zhuǎn)JPG
            if filename.lower().endswith('.png'):
                img.save(output_path)
            else:
                img.save(output_path, quality=90) # JPG格式,需要質(zhì)量參數(shù)
            
            print(f"? 添加水?。?{filename}' -> '{os.path.basename(output_path)}'")
            img.close()
        except Exception as e:
            print(f"? 添加水印失?。?{filename}'。錯誤信息:{e}")
    print("? 批量添加文字水印完成!")

if __name__ == "__main__":
    source_dir = os.path.expanduser("~/Desktop/待加水印圖片")
    output_dir = os.path.expanduser("~/Desktop/已加文字水印")
    os.makedirs(source_dir, exist_ok=True)

    # 準備一些圖片到 source_dir (JPG, PNG都可以)

    # 示例1:批量添加半透明灰色版權(quán)聲明到右下角
    add_text_watermark_batch(
        source_dir, 
        output_dir, 
        watermark_text="? Python自動化博主 All Rights Reserved",
        font_path="arial.ttf", 
        font_size=30, 
        text_color=(128, 128, 128, 150), # 半透明灰色
        position="bottom_right"
    )

    # 示例2:批量添加紅色居中“內(nèi)部資料”水印
    # add_text_watermark_batch(
    #     source_dir, 
    #     output_dir, 
    #     watermark_text="內(nèi)部資料,嚴禁外傳",
    #     font_path="simhei.ttf", # 嘗試其他字體,如SimHei (黑體)
    #     font_size=50, 
    #     text_color=(255, 0, 0, 100), # 半透明紅色
    #     position="center"
    # )

操作步驟:

準備圖片: 在桌面創(chuàng)建一個名為待加水印圖片的文件夾,放入一些測試圖片。

修改代碼路徑: 修改 source_dir 和 output_dir 為你實際的文件夾路徑。

運行: 運行 python ImageTextWatermarkBatch.py。你可以修改水印文字、字體、顏色、透明度和位置來嘗試不同效果。

效果展示:

2.2 批量添加圖片水印:Logo、二維碼,品牌宣傳一步到位!

我們有的時候需要對所有產(chǎn)品圖、宣傳圖批量加上公司Logo、品牌圖標,或者為了推廣,為圖片添加公眾號二維碼。手動粘貼Logo不僅慢,還很難保證位置和大小的一致性。

利用Pillow庫,我們可以將Logo圖片(或二維碼)作為水印,批量添加圖片水印到你的目標圖片上。

from PIL import Image
import os

def add_image_watermark_batch(source_folder, output_folder, watermark_image_path,
                              position="bottom_right", opacity=0.5, size_ratio=0.15):
    """
    批量給指定文件夾下的圖片添加圖片水?。↙ogo或二維碼)。
    這是高效的Python批量添加圖片水印腳本。
    :param source_folder: 源圖片文件夾路徑
    :param output_folder: 輸出文件夾路徑
    :param watermark_image_path: 水印圖片(Logo)的路徑 (最好是帶透明背景的PNG圖)
    :param position: 水印位置 ("top_left", "top_right", "bottom_left", "bottom_right", "center", "tile")
                    "tile" 表示平鋪水印
    :param opacity: 水印透明度 (0.0-1.0)
    :param size_ratio: 水印圖片相對于主圖的尺寸比例 (0.0-1.0)
    """
    if not os.path.exists(source_folder):
        print(f"? 源文件夾不存在:{source_folder}")
        return
    if not os.path.exists(watermark_image_path):
        print(f"? 水印圖片不存在:{watermark_image_path}")
        return

    os.makedirs(output_folder, exist_ok=True)
    files = [f for f in os.listdir(source_folder) if os.path.isfile(os.path.join(source_folder, f))]

    try:
        watermark_img = Image.open(watermark_image_path)
        # 轉(zhuǎn)換水印圖片為RGBA模式,確保透明度正常處理
        if watermark_img.mode != 'RGBA':
            watermark_img = watermark_img.convert('RGBA')
    except Exception as e:
        print(f"? 無法加載水印圖片:{e}")
        return

    print(f"?? 正在批量為 '{source_folder}' 下的圖片添加圖片水印...")
    for filename in files:
        source_path = os.path.join(source_folder, filename)
        output_path = os.path.join(output_folder, "watermarked_" + filename)
        
        try:
            main_img = Image.open(source_path).convert("RGBA") # 主圖也轉(zhuǎn)為RGBA

            # 調(diào)整水印圖片大小
            # 如果是平鋪水印,尺寸比例可以非常小
            if position == "tile":
                resized_watermark = watermark_img.resize((int(watermark_img.width * size_ratio / 5), int(watermark_img.height * size_ratio / 5)), Image.LANCZOS)
            else:
                resized_watermark = watermark_img.resize((int(main_img.width * size_ratio), int(main_img.height * size_ratio)), Image.LANCZOS)
            
            # 調(diào)整水印透明度
            alpha = resized_watermark.split()[-1] # 獲取透明通道
            alpha = Image.eval(alpha, lambda x: x * opacity) # 調(diào)整透明度
            resized_watermark.putalpha(alpha)

            # 根據(jù)位置計算粘貼坐標
            if position == "top_left":
                x, y = 10, 10
            elif position == "top_right":
                x, y = main_img.width - resized_watermark.width - 10, 10
            elif position == "bottom_left":
                x, y = 10, main_img.height - resized_watermark.height - 10
            elif position == "bottom_right":
                x, y = main_img.width - resized_watermark.width - 10, main_img.height - resized_watermark.height - 10
            elif position == "center":
                x, y = (main_img.width - resized_watermark.width) // 2, (main_img.height - resized_watermark.height) // 2
            elif position == "tile": # 平鋪水印
                for i in range(0, main_img.width + resized_watermark.width, resized_watermark.width + 50): # 50為水印間距
                    for j in range(0, main_img.height + resized_watermark.height, resized_watermark.height + 50):
                        main_img.alpha_composite(resized_watermark, (i, j))
                # 平鋪完成后直接保存,跳過下面的單次粘貼
                main_img.save(output_path)
                print(f"? 添加平鋪水?。?{filename}' -> '{os.path.basename(output_path)}'")
                main_img.close()
                continue # 跳到下一個文件

            # 單次水印粘貼 (非平鋪模式)
            main_img.alpha_composite(resized_watermark, (x, y)) # 將水印粘貼到主圖上
            
            # 保存圖片,如果原始是PNG且有透明度需求,可以嘗試保存回PNG,否則轉(zhuǎn)JPG
            if filename.lower().endswith('.png') and Image.open(source_path).mode == 'RGBA':
                main_img.save(output_path)
            else:
                main_img.save(output_path, quality=90) # JPG格式
            
            print(f"? 添加水?。?{filename}' -> '{os.path.basename(output_path)}'")
            main_img.close()
        except Exception as e:
            print(f"? 添加水印失?。?{filename}'。錯誤信息:{e}")
    watermark_img.close() # 關(guān)閉水印圖片
    print("? 批量添加圖片水印完成!")

if __name__ == "__main__":
    source_dir = os.path.expanduser("~/Desktop/待加Logo圖片")
    output_dir = os.path.expanduser("~/Desktop/已加Logo水印")
    watermark_file = os.path.expanduser("~/Desktop/my_logo.png") # 你的Logo圖片路徑 (建議PNG透明背景)
    
    os.makedirs(source_dir, exist_ok=True)
    
    # 準備測試圖片到 source_dir,準備一個Logo圖片到桌面

    # 示例1:批量添加右下角半透明Logo
    add_image_watermark_batch(
        source_dir, 
        output_dir, 
        watermark_file,
        position="bottom_right", 
        opacity=0.6,    # 60%透明度
        size_ratio=0.15 # 水印大小為主圖的15%
    )

    # 示例2:批量添加平鋪水?。ㄟm合防盜圖)
    # add_image_watermark_batch(
    #     source_dir, 
    #     output_dir, 
    #     watermark_file,
    #     position="tile", 
    #     opacity=0.1,    # 平鋪水印通常透明度更低
    #     size_ratio=0.5 # 平鋪水印的單個水印尺寸可以更大一些
    # )

操作步驟:

  • 準備圖片: 創(chuàng)建一個名為待加Logo圖片的文件夾,放入一些測試圖片。
  • 準備Logo: 準備一個Logo圖片(最好是透明背景的PNG格式),命名為my_logo.png,放在桌面。
  • 修改代碼路徑: 修改 source_dir、output_dir 和 watermark_file。

運行: 運行 python ImageImageWatermarkBatch.py。你可以修改水印位置、透明度和大小比例來嘗試不同效果。

效果展示:

3. 實戰(zhàn):你的“圖片批量加水印神器”可視化工具雛形

現(xiàn)在,你已經(jīng)掌握了Python批量圖片加水印的各項核心技巧。是時候?qū)⑦@些能力整合,構(gòu)建一個屬于你的圖片批量加水印神器”自動化工具了!就像我們之前的“一鍵文件整理器”一樣,這個工具也將是可配置、易操作的。

核心理念: 提供一個統(tǒng)一的Python腳本,通過修改一個config_watermark.yaml配置文件,就能同時控制文字水印和圖片水印的各種參數(shù),實現(xiàn)一鍵式圖片版權(quán)保護。

config_watermark.yaml (配置文件示例,與 watermark_processor_main.py 放在同一目錄):

config_watermark.yaml - 你的圖片批量加水印配置

— 文件夾路徑配置 —

source_directory: “D:\lx\sourcelogo待加水印圖片源”
output_directory: “D:\lx\destlogo已加水印圖片結(jié)果”

水印規(guī)則配置

可以同時啟用或禁用文字水印和圖片水印規(guī)則 watermark_rules:

type: “text” # 文字水印規(guī)則
enabled: true # 是否啟用此規(guī)則
text: “? 你的公司名稱 / 你的個人品牌” # 水印文字內(nèi)容
font_path: “arial.ttf” # 字體文件路徑,確保系統(tǒng)有該字體或提供完整路徑
font_size: 30
text_color: [0, 0, 0, 128] # 文字顏色 (R, G, B, Alpha透明度0-255)
position: “bottom_right” # 位置: top_left, top_right, bottom_left, bottom_right, center

offset: [10, 10] # 可選:在position基礎上再偏移像素 [x, y]

type: “image” # 圖片水印規(guī)則 (如Logo, 二維碼)
enabled: false # 是否啟用此規(guī)則
watermark_image_path: “~/Desktop/your_logo.png” # 你的Logo圖片路徑 (建議PNG透明背景)
position: “bottom_left” # 位置: top_left, top_right, bottom_left, bottom_right, center, tile (平鋪)
opacity: 0.7 # 透明度 (0.0-1.0)
size_ratio: 0.1 # 水印圖片相對于主圖的尺寸比例 (0.0-1.0)

主要程序展示

from PIL import Image, ImageDraw, ImageFont
import os
import yaml
import shutil

以下是前面章節(jié)中講解的各項加水印功能函數(shù),請確保它們都已復制到這里,這里演示大致思路。

def _apply_single_watermark(img_obj, watermark_config, img_path):
    """
    根據(jù)單個水印規(guī)則給圖片對象添加水印。
    :param img_obj: PIL圖片對象
    :param watermark_config: 單個水印規(guī)則字典
    :param img_path: 原始圖片路徑 (用于日志和錯誤處理)
    """
    w_type = watermark_config.get("type")
    
    if not watermark_config.get("enabled", True): # 檢查是否啟用
        return img_obj # 未啟用,返回原圖

    if w_type == "text":
        text_content = watermark_config.get("text", "")
        font_path = watermark_config.get("font_path", "arial.ttf")
        font_size = watermark_config.get("font_size", 30)
        text_color = tuple(watermark_config.get("text_color", [0, 0, 0, 128]))
        position = watermark_config.get("position", "bottom_right")

        draw = ImageDraw.Draw(img_obj)
        try:
            font = ImageFont.truetype(font_path, font_size)
        except IOError:
            print(f"?? 字體文件 '{font_path}' 未找到,使用默認字體。")
            font = ImageFont.load_default()

        # 計算文字位置
        bbox = draw.textbbox((0, 0), text_content, font=font)
        text_width = bbox[2] - bbox[0]
        text_height = bbox[3] - bbox[1]
        
        x, y = 0, 0
        if position == "top_left": x, y = 10, 10
        elif position == "top_right": x, y = img_obj.width - text_width - 10, 10
        elif position == "bottom_left": x, y = 10, img_obj.height - text_height - 10
        elif position == "bottom_right": x, y = img_obj.width - text_width - 10, img_obj.height - text_height - 10
        elif position == "center": x, y = (img_obj.width - text_width) // 2, (img_obj.height - text_height) // 2
        
        draw.text((x, y), text_content, font=font, fill=text_color)
        print(f"   - 添加文字水印: '{text_content}'")
        return img_obj # 返回處理后的圖片對象

    elif w_type == "image":
        watermark_img_path = watermark_config.get("watermark_image_path")
        position = watermark_config.get("position", "bottom_right")
        opacity = watermark_config.get("opacity", 0.5)
        size_ratio = watermark_config.get("size_ratio", 0.15)

        if not os.path.exists(watermark_img_path):
            print(f"? 水印圖片文件不存在:{watermark_img_path}")
            return img_obj

    
  return img_obj


def run_watermark_processor(config_path):
    """
    運行圖片水印處理器,根據(jù)配置文件批量添加水印。
    這是你的“圖片批量加水印神器”的核心。
    :param config_path: 配置文件的路徑
    """
    try:
        with open(config_path, 'r', encoding='utf-8') as f:
            config = yaml.safe_load(f)
    except FileNotFoundError:
        print(f"? 配置文件未找到:{config_path}")
        return
    except yaml.YAMLError as e:
        print(f"? 配置文件解析錯誤:{e}")
        return

    source_dir = os.path.expanduser(config.get("source_directory"))
    output_dir = os.path.expanduser(config.get("output_directory"))
    
if __name__ == "__main__":
    # 確保 config_watermark.yaml 在同一目錄下
    config_file_path = os.path.join(os.path.dirname(__file__), "config_watermark.yaml") 
    run_watermark_processor(config_file_path)

操作步驟:

準備環(huán)境: 確保你已經(jīng)安裝了Pillow (pip install Pillow) 和 PyYAML (pip install pyyaml)。

創(chuàng)建文件: 創(chuàng)建一個源文件夾,放入各種你希望處理的圖片文件。

準備Logo(如果使用圖片水印): 準備一個Logo圖片(最好是透明背景的PNG格式),命名為your_logo.png,放在與watermark_processor_main.py和config_watermark.yaml同一目錄下。

保存代碼: 將上面的 watermark_processor_main.py 和 config_watermark.yaml 兩個文件保存到同一個目錄下。

修改配置: 打開 config_watermark.yaml,根據(jù)你實際的文件夾路徑修改 source_directory 和 output_directory。啟用/禁用你需要的文字水印或圖片水印規(guī)則,并調(diào)整其參數(shù)(文字內(nèi)容、字體、顏色、位置,或Logo路徑、透明度、大?。?。

運行: 在終端中進入 watermark_processor_main.py 所在的目錄,運行 python watermark_processor_main.py。

下面是批量加水印流程演示圖:

A[開始] --> B{加載 config_watermark.yaml};
B --> C[獲取源文件夾圖片列表];
C -- 遍歷每張圖片 --> D{打開圖片,轉(zhuǎn)為RGBA模式};
D -- 檢查 watermark_rules --> E{對每條啟用規(guī)則};
E -- text --> F[添加文字水印];
E -- image --> G[添加圖片水印];
F --> H[將處理后的圖片保存到輸出目錄];
G --> H;
H --> I[處理下一個圖片];
I -- 所有圖片處理完畢 --> J[結(jié)束];

告別手動P圖,你的視覺內(nèi)容從此自帶“版權(quán)”!

恭喜你!通過本篇文章,你已經(jīng)掌握了Python圖片處理的又一項強大魔法——圖片批量加水?。∥覀儚膱D片版權(quán)保護和品牌宣傳的痛點出發(fā),學會了如何:

Pillow庫與ImageDraw: 掌握Python繪制文字和圖形的核心工具。

Python批量添加文字水?。?自定義水印文字、字體、顏色、透明度和位置,為你的圖片打上專屬標簽。

Python批量添加圖片水?。?輕松疊加Logo、二維碼等圖片水印,提升品牌辨識度。

構(gòu)建可配置工具: 通過簡單的配置文件,一鍵管理你的所有圖片加水印需求。

現(xiàn)在,你不再需要手動打開PS,一張張為圖片加水印。你只需準備好圖片和水印素材,修改一下配置文件,運行腳本,你的海量作品就能一鍵擁有版權(quán)信息或品牌Logo,實現(xiàn)高效的圖片自動化!讓你的視覺內(nèi)容更專業(yè)、更安全!

除了水印,你還希望Python能幫你實現(xiàn)哪些圖片處理的自動化功能?比如批量裁剪、智能調(diào)色,或者圖片風格轉(zhuǎn)換?你會在哪些場景下使用這個批量加水印神器?

以上就是基于Python實現(xiàn)圖片批量加水印的方法的詳細內(nèi)容,更多關(guān)于Python圖片批量加水印的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Python中Selenium模擬JQuery滑動解鎖實例

    Python中Selenium模擬JQuery滑動解鎖實例

    這篇文章主要介紹了Python中Selenium模擬JQuery滑動解鎖實例,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • 一文帶你搞懂Numpy中的深拷貝和淺拷貝

    一文帶你搞懂Numpy中的深拷貝和淺拷貝

    深拷貝和淺拷貝是Python中重要的概念,本文將重點介紹在NumPy中深拷貝和淺拷貝相關(guān)操作的定義和背后的原理,快跟隨小編一起來學習一下吧
    2022-04-04
  • 利用Python批量提取Win10鎖屏壁紙實戰(zhàn)教程

    利用Python批量提取Win10鎖屏壁紙實戰(zhàn)教程

    這篇文章主要給大家介紹了關(guān)于利用Python批量提取Win10鎖屏壁紙的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。
    2018-03-03
  • 基于FME使用Python過程圖解

    基于FME使用Python過程圖解

    這篇文章主要介紹了基于FME使用Python過程圖解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-05-05
  • python如何調(diào)用字典的key

    python如何調(diào)用字典的key

    在本篇文章里小編給大家分享的是關(guān)于python調(diào)用字典的key方法實例,有興趣點朋友們可以參考學習下。
    2020-05-05
  • 基于Python實現(xiàn)在線加密解密網(wǎng)站系統(tǒng)

    基于Python實現(xiàn)在線加密解密網(wǎng)站系統(tǒng)

    在這個數(shù)字化時代,數(shù)據(jù)的安全和隱私變得越來越重要,所以本文小編就來帶大家實現(xiàn)一個簡單但功能強大的加密解密系統(tǒng),并深入探討它是如何工作的,有興趣的可以了解下
    2023-09-09
  • 在pandas中更改列類型方式

    在pandas中更改列類型方式

    這篇文章主要介紹了在pandas中更改列類型方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2025-10-10
  • 10個python爬蟲入門基礎代碼實例 + 1個簡單的python爬蟲完整實例

    10個python爬蟲入門基礎代碼實例 + 1個簡單的python爬蟲完整實例

    這篇文章主要介紹了10個python爬蟲入門基礎代碼實例和1個簡單的python爬蟲爬蟲貼吧圖片的實例,需要的朋友可以參考下
    2020-12-12
  • Flask藍圖學習教程

    Flask藍圖學習教程

    在Flask中,使用藍圖Blueprint來分模塊組織管理。藍圖實際可以理解為是一個存儲一組視圖方法的容器對象,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習吧
    2022-10-10
  • python 實現(xiàn)提取log文件中的關(guān)鍵句子,并進行統(tǒng)計分析

    python 實現(xiàn)提取log文件中的關(guān)鍵句子,并進行統(tǒng)計分析

    今天小編就為大家分享一篇python 實現(xiàn)提取log文件中的關(guān)鍵句子,并進行統(tǒng)計分析,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12

最新評論

花莲县| 望城县| 北碚区| 南昌市| 安顺市| 琼中| 延安市| 奈曼旗| 横峰县| 曲阜市| 西乡县| 仲巴县| 曲靖市| 辉县市| 阜城县| 海晏县| 镇安县| 钟祥市| 凤城市| 凯里市| 温州市| 平安县| 巨野县| 体育| 清镇市| 保德县| 梅州市| 竹北市| 江门市| 志丹县| 白沙| 郎溪县| 蓬溪县| 合阳县| 宝清县| 邓州市| 合川市| 来宾市| 石泉县| 耿马| 涿鹿县|