当前位置:   article > 正文

python,html转成图片格式_python html转图片

python html转图片
# -*- 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)


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/204542
推荐阅读
相关标签
  

闽ICP备14008679号