赞
踩
# -*- coding:utf-8 -*- # Time:2023/6/13 11:07 # Author:Xue # FileName:html_image.py import imgkit options = { "encoding": "UTF-8", # 设置编码格式,这边utf8是个示例,具体用哪个编码还要看你的html文件用什么 'javascript-delay': '2000', # 设置等待javascript渲染时间 "custom-header": [('Accept-Encoding', 'gzip')], # 下面的是设置图片的样式 # 'page-size': 'A3', # 'margin-top': '0.75in', # 'margin-right': '0.75in', # 'margin-bottom': '0.75in', # 'margin-left': '0.75in', # 'no-outline': False } path_wkimg = r'D:\PyCharm\wkhtmltopdf\bin\wkhtmltoimage.exe' # 工具路径 cfg = imgkit.config(wkhtmltoimage=path_wkimg) # 1、将html文件转为图片 imgkit.from_file(r'D:\python\lianxi\study\file\ceshi.html', 'helloworld.jpg', config=cfg, options=options) # # 2、从url获取html,再转为图片 # imgkit.from_url('https://httpbin.org/ip', 'ip.jpg', config=cfg) # # 3、将字符串转为图片 # imgkit.from_string('Hello!','hello.jpg', config=cfg)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。