Blogger Information
Blog 55
fans 0
comment 0
visits 59280
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
HTML转图片的JS插件-rasterizeHTML.js
南鸢离梦的博客
Original
2670 people have browsed it

在WEB前端工作中,有时需要实现对页面生成缩略图的功能。rasterizeHTML.js就可以将HTML渲染到浏览器的canvas中,直接用JS插件达到生成图片的效果。rasterizeHTML.js为我们提供了三个方法:rasterizeHTML.drawURL( url [, canvas] [, options] )根据URL生成canvas,

rasterizeHTML.drawHTML( html [, canvas] [, options] )根据HTML代码生成,

rasterizeHTML.drawDocument( document [, canvas] [, options] )根据文档生成。下面详细的介绍一下HTML转图片的JS插件-rasterizeHTML.js。

1、引入rasterizeHTML.js

  1. <script type="text/javascript" src="rasterizeHTML.allinone.js"></script>

2、创建一个canvas,rasterizeHTML.js生成图片

  1. var canvas = document.getElementById("canvas");
  2. rasterizeHTML.drawHTML('Some ' + '<span style="color: green; font-size: 20px;">HTML</span>' + ' with an image', canvas);

注意:drawURL()加载的URL必须是同域名URL或者是支持跨域的URL。

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post