HTML存為圖片的Java類庫:Html2Image

jopen 12年前發布 | 50K 次閱讀 Java 圖形/圖像處理

Html2Image 是一個 Java 類庫用于將 HTML標記存為 GIF\PNG 和 JPG 圖片,并通過HTML的<map> 標簽展示該圖片。

使用案例:

  • 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 (<img/>) and client-side image-map (<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.

示例代碼:

HtmlImageGenerator imageGenerator = new HtmlImageGenerator();
imageGenerator.loadHtml("<b>Hello World!</b> Please goto <a title=\"Goto Google\" href=\"http://www.google.com\">Google</a>.");
imageGenerator.saveAsImage("hello-world.png");
imageGenerator.saveAsHtmlWithMap("hello-world.html", "hello-world.png");

項目主頁:http://www.baiduhome.net/lib/view/home/1350864881680

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!