Mac 终端中自定义大小的 Html2png 转换

Mac 终端中自定义大小的 Html2png 转换

我需要批量将 html 文件转换为 png,图片周围没有白色区域。html 文件的背景上有两行文本。背景图像附加在 html 文件的头部部分,带有 css 代码。我尝试了一些转换选项,xhtmltopdf但最终得到的是 A4 pdf,实际图片周围有很多空白。我最初的想法是先创建 pdf,然后将其转换为 png。也许有人知道更好的方法?任何帮助都将不胜感激!这是我的代码。

<html>
<head>
<title></title>
<meta charset="UTF-8">
<style type="text/css">
.cover
{
    text-align: center;
    background: url(cover01.jpg) no-repeat ;
    width: 270px ;
    height: 396px ;
    padding: 15px center ;
    background-clip: border-box ;
    background-origin: border-box ;
    line-height: 130px ;
    font-size: x-large ;
}
.author
{
text-align:center
}
.booktitle
{
text-align:center
}
span
{
  display: inline-block;
  vertical-align: middle;
  line-height: normal;      
}
</style>
</head>
<body>
<div class="cover" background="cover01.jpg">

<p class="author">Jean Ziminne</p>
<span>
<p class="booktitle">Deep into the steppe</p></span>
</div>
</body>
</html>

答案1

这个python脚本应该可以很好地为你工作:)希望如此..

https://github.com/paulhammond/webkit2png

webkit2png 是一个用于创建网页截图的命令行工具

示例用法

webkit2png http://www.google.com/             # screengrab google
webkit2png -W 1000 -H 1000 http://google.com/ # bigger screengrab of google
webkit2png -T http://google.com/              # just the thumbnail screengrab
webkit2png -TF http://google.com/             # just thumbnail and fullsize grab
webkit2png -o foo http://google.com/          # save images as "foo-thumb.png" etc
webkit2png -                                  # screengrab urls from stdin
webkit2png /path/to/file.html                 # screengrab local html file
webkit2png -h | less                          # full documentation"""

相关内容