Golang html转换图片,将HTML转换为图像

这篇博客介绍了一个在Windows和Linux上将带有语法高亮的源代码以HTML格式导出并转换为PNG图像的解决方案。涉及的工具有gvim、moria、wkhtmltoimage、gawk、sed和ImageMagick。该过程包括删除HTML的背景属性、转换为PNG、修剪边距并添加边框。此外,还提供了安装指南、环境变量设置和批处理文件示例。
摘要由CSDN通过智能技术生成

软件需求

以下软件包可用于Windows和Linux系统,并且是完整,有效的解决方案所必需的:

gvim - Used to export syntax highlighted source code to HTML.

moria - Colour scheme for syntax highlighting.

wkhtmltoimage - Used to convert HTML documents to PNG files.

gawk and sed - Text processing tools.

ImageMagick - Used to trim the PNG and add a border.

一般步骤

解决方案的工作原理如下:

Load the source code into an editor that can add splashes of colour.

Export the source code as an HTML document (with embedded FONT tags).

Strip the background attribute from the HTML document (to allow transparency).

Convert the HTML document to a PNG file.

Trim the PNG border.

Add a small, 25 pixel border around the image.

Delete temporary files.

该脚本为包含长度均小于80个字符的行的源文件生成宽度完全相同的图像。行长超过80个字符的源文件会生成足够宽的图像,以保留整行。

安装

将组件安装到以下位置:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值