• 请不要在回答技术问题时复制粘贴 AI 生成的内容
cyhone
V2EX  ›  程序员

用 Python 给图片加文字水印

  •  
  •   cyhone · Jul 11, 2018 · 3865 views
    This topic created in 2863 days ago, the information mentioned may be changed or developed.

    使用 Python 为图片加文字水印

    https://github.com/chenyahui/practical_tools/tree/master/watermark

    特性

    • 支持批量添加
    • 支持多行水印的添加
    • 可定制的水印的字体、颜色和大小
    • 文字自适应图片分辨率大小

    使用

    批量为一个文件夹中所有图片添加水印

     batch_add_waterwalk("input_dir/","output_dir/", ["测试水印"]) 
    

    为单个图片添加水印

    add_watermark("input.jpg","output.jpg",["测试水印"])
    

    配置项

    config = {
        "font": 'C:/windows/fonts/simsun.ttc', # 字体位置
        'text-width': 0.8, # 文字占图片的宽度
        'rgba': (0, 0, 255, 100), # rgba
        'allow_ext': ['png', 'jpg', 'jpeg'] # 允许的后缀
    }
    

    依赖

    PIL

    3 replies    2018-07-11 18:14:37 +08:00
    designer
        1
    designer  
       Jul 11, 2018 via iPhone   ❤️ 1
    支持下
    xubeiyan
        2
    xubeiyan  
       Jul 11, 2018
    PIL 已经停止维护,建议使用 Pillow
    mashirozx
        3
    mashirozx  
       Jul 11, 2018 via Android
    @xubeiyan pillow 还是写成从 PIL 导入的
    from PIL import
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3309 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 11:46 · PVG 19:46 · LAX 04:46 · JFK 07:46
    ♥ Do have faith in what you're doing.