python遍历目录加水印

  • Post author:
  • Post category:python
  • Post comments:0评论

python遍历目录加水印

from watermarker.marker import  add_mark
import os
import shutil

def mark(file, outdir, mark = "火苗999℃"):
    add_mark(file = file, out = outdir, mark = mark
            #, color = "#000000"
            , opacity=0.1, angle=30, space=300, size=20)
    return 

def mark_dir2(root, out):
    if not os.path.exists(out):
        # os.path.isdir(out):
        os.mkdir(out)
    files = os.listdir(root)
    for fname in files:
        fpath = root + "\\" + fname
        if os.path.isfile(fpath):   # not a dir
            file_name, file_extension = os.path.splitext(fpath)
            if ".gif" != file_extension:
                mark(fpath, out)
            else:
                shutil.copy(fpath, out + "\\" + fname)
        elif os.path.isdir(fpath):  # is a dir
            subdir = root + "\\" + fname
            subout =  out + "\\" + fname
            mark_dir2(subdir, subout)
        else :
            print("no defined {}!".format(fpath))
    return 

if __name__ == '__main__' :
    src = 'H:\\myblog\\blog\\source\\picture\\src'
    out = 'H:\\myblog\\blog\\source\\picture\\mark'
    mark_dir2(src, out)

old

new

文章作者: 张拓
文章链接: http://www.xssl.online/python%e9%81%8d%e5%8e%86%e7%9b%ae%e5%bd%95%e5%8a%a0%e6%b0%b4%e5%8d%b0/
版权声明: 本博客所有文章除特别声明外,均采用CC BY-NC-SA 4.0 许可协议。转载请注明来自 张拓的博客
浏览次数: 633

张拓

陕西西安蓝田张拓QQ1070410059。一生所求不过“心安”二字。 然,尘世多纷扰。

发表回复