html2image Java HTML 转图片工具

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

未来AI编程

共鸣===鼓励 打赏您随意

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值