html2image Java HTML 转图片工具

举报
隔壁老汪 发表于 2022/06/24 00:37:31 2022/06/24
【摘要】 html2image html2image migration from https://code.google.com/p/java-html2image/ by Yoav Aharoni This simple Java library converts plain HTML markup to image...

html2image

html2image

migration from https://code.google.com/p/java-html2image/ by Yoav Aharoni

This simple Java library converts plain HTML markup to image and provides client-side image-map using HTML element.

What Can I Do With It: Use Cases

  • Programmatically compose images - Use case: You need to compose images from other images and texts.
    • Solution - Create a web page using plain HTML, CSS and image and use Html2Image to convert it to an image.
  • Improve your spam - Use case: You need to send decorative HTML email.
    • You craft your HTML using CSS, images and links.
    • Alas, your clients open their Outlook, Gmail or any other mail client mailbox, and find your mail all scrambled up (merely resembles the presentation of the same HTML in a browser).
    • That's because Outlook and other clients only support limited functionality of HTML and have different implementations and bugs.
    • Solution - Use Html2Image to convert your original mail's HTML to a new HTML containing only image () and client-side image-map () for the links in the original HTML.
    • This also allow you to easily use unique fonts in your mail.
  • Prevent spamming - Use case: Your website has a list of contacts and their email addresses.
    • The email addresses are in plain text, allowing robots and spiders to harvest these addresses and spam your team with Viagra ads.
    • Solution - Use Html2Image to convert those email addresses to images.

What Do I Give and What Do I Get

Html2Image allows you to transform this HTML markup:

 
 

To this visually equivalent HTML markup:

 
 

Supported Images Formats

Html2Image allows you to save your HTML as GIF, PNG or JPEG image.

API Html2Image as only one useful Java class, HtmlImageGenerator.

Common usage is this:

 
 

Which will generate hello-world.png image of the HTML and hello-world.html file containing client-side image-map (as in the example above).

HtmlImageGenerator Methods

  • loadUrl(url) - Loads HTML from URL object or URL string.
  • loadHtml(html) - Loads HTML source.
  • saveAsImage(file) - Save loaded HTML as image.
  • saveAsHtmlWithMap(file, imageUrl) - Creates an HTML file containing client-side image-map generated from HTML's links.
  • getLinks() - List all links in the HTML document and their corresponding href, target, title, position and dimension.
  • getBufferedImage() - Get AWT buffered image of the HTML.
  • getLinksMapMarkup(mapName) - Get HTML snippet of the client-side image-map generated from the links.
  • get/setOrientation(orientation) - Get/Set document orientation (left-to-right or right-to-left).
  • get/setSize(dimension) - Get/Set size of the generated image.

https://github.com/thon-ju/html2image

文章来源: blog.csdn.net,作者:隔壁老瓦,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/wxb880114/article/details/105754488

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。