press_sec_bot_plus.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:PressSecBotPlus 作者: robmathers 项目源码 文件源码
def html_to_png(html):
    # Use a temp file in the current working directory so that wkhtmltoimage handles relative URLs properly
    temp_file = '.temp.html'
    with open(temp_file, 'w') as f:
        f.write(html.encode('utf-8'))

    command = ['wkhtmltoimage']
    if not find_executable(command[0]):
        raise ImportError('%s not found' % command[0])

    command += ['-f', 'png'] # format output as PNG
    command += ['--zoom', '2'] # retina image
    command += ['--width', '750'] # viewport 750px wide
    command += [temp_file] # read from stdin
    command += ['-'] # write to stdout

    wkhtml_process = Popen(command, stdout=PIPE, stderr=PIPE)
    (output, err) = wkhtml_process.communicate()

    os.remove(temp_file)

    image = Image.open(BytesIO(output))
    image = set_transparent_pixel(image)

    return image
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号