|
1 | 1 | <?xml version="1.0"?> |
2 | | -<document> |
| 2 | +<document xmlns="http://maven.apache.org/XDOC/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 3 | + xsi:schemaLocation="https://maven.apache.org/XDOC/2.0 https://maven.apache.org/xsd/xdoc-2.0.xsd"> |
3 | 4 |
|
4 | 5 | <properties> |
5 | 6 | <title>Image format support</title> |
| 7 | + <author>RBRi</author> |
6 | 8 | </properties> |
7 | 9 |
|
8 | 10 | <body> |
9 | | - <section name="General"> |
| 11 | + |
| 12 | + <macro name="toc"/> |
| 13 | + |
| 14 | + <section name="General" id="general"> |
10 | 15 | <p> |
11 | | - Because HtmlUnit is a headless browsers you might think HtmlUnit can be agnostic to image formats. |
12 | | - This is in general true but not if you look at the details. Even if HtmlUnit is headless there is |
13 | | - still support for layout related methods like Element.getBoundingClientRect(). A second case is |
14 | | - Canvas.drawImage(). To support this HtmlUnit has to be able to determine the dimensions of a given |
15 | | - image (for the first case) and produce a raster version (for the second case). |
| 16 | + Because HtmlUnit is a headless browser, you might think HtmlUnit can be agnostic to image formats[cite: 13]. |
| 17 | + This is generally true, but not when inspecting layout-related details[cite: 13]. Even though HtmlUnit |
| 18 | + is headless, there is still support for layout-related methods like <code>Element.getBoundingClientRect()</code>. |
| 19 | + A second case is <code>Canvas.drawImage()</code>. |
| 20 | + To support these, HtmlUnit must determine the dimensions of a given image (for layout calculations) and render |
| 21 | + a rasterized version (for canvas operations). |
16 | 22 | </p> |
17 | 23 | <p> |
18 | | - For this HtmlUnit uses <a href="https://docs.oracle.com/javase/8/docs/api/javax/imageio/package-summary.html">ImageIO</a>. |
19 | | - Sadly there is only support for JPEG, PNG, BMP, WBMP and GIF. |
| 24 | + For image processing, HtmlUnit uses Java's <a href="https://docs.oracle.com/javase/8/docs/api/javax/imageio/package-summary.html">ImageIO</a>. |
| 25 | + Out of the box, standard ImageIO only supports JPEG, PNG, BMP, WBMP, and GIF. |
20 | 26 | </p> |
21 | 27 | <p> |
22 | | - If HtmlUnit has to deal with the details of an unsupported image format a message is shown in the log and |
23 | | - the image is (more or less) ignored. |
| 28 | + When HtmlUnit encounters an unsupported image format, a warning is recorded in the log and |
| 29 | + the image is generally ignored. |
24 | 30 | </p> |
25 | 31 | <p> |
26 | | - To overcome this limitation you have to install support for more file formats from |
27 | | - <a href="https://github.com/haraldk/TwelveMonkeys">TwelveMonkeys</a> |
| 32 | + To overcome this limitation, you can install additional format plugins, such as those provided by |
| 33 | + <a href="https://github.com/haraldk/TwelveMonkeys">TwelveMonkeys</a>. |
28 | 34 | </p> |
29 | | - <subsection name="Example"> |
| 35 | + |
| 36 | + <subsection name="Example" id="example"> |
30 | 37 | <p> |
31 | | - Add svg support to be able to include SVG images into your canvas drawings<br/> |
32 | | - This is simply done by adding some dependencies to your project: |
| 38 | + To enable SVG support for drawing SVG images onto HTML5 canvases, add the required dependencies |
| 39 | + to your project's <code>pom.xml</code> file: |
33 | 40 | </p> |
34 | | -<source> |
35 | | -<![CDATA[ <dependency> |
| 41 | +<source><![CDATA[<dependency> |
36 | 42 | <groupId>com.twelvemonkeys.imageio</groupId> |
37 | 43 | <artifactId>imageio-batik</artifactId> |
38 | | - <version>3.6.4</version> |
| 44 | + <version>3.14.0</version> |
39 | 45 | </dependency> |
40 | 46 | <dependency> |
41 | 47 | <groupId>org.apache.xmlgraphics</groupId> |
42 | 48 | <artifactId>batik-transcoder</artifactId> |
43 | | - <version>1.17</version> |
| 49 | + <version>1.19</version> |
44 | 50 | <exclusions> |
45 | 51 | <exclusion> |
46 | 52 | <groupId>commons-logging</groupId> |
|
54 | 60 | </dependency> |
55 | 61 | ]]></source> |
56 | 62 | <p> |
57 | | - To make sure everything is working you can execute this code and check if you get a BufferedImage. |
| 63 | + To verify that image decoding works as expected, run this snippet to confirm a valid <code>BufferedImage</code> is created[cite: 13]: |
58 | 64 | </p> |
59 | | -<source> |
60 | | -<![CDATA[ final String svg = "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns=\"http://www.w3.org/2000/svg\">" |
61 | | - + "<circle cx=\"5\" cy=\"5\" r=\"4\" stroke=\"black\" stroke-width=\"1\" fill=\"red\" />" |
62 | | - + "</svg>"; |
63 | | - BufferedImage img = ImageIO.read(new ByteArrayInputStream(svg.getBytes(StandardCharsets.US_ASCII))); |
64 | | - System.out.println(img);]]></source> |
| 65 | + <source><![CDATA[final String svg = "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns=\"http://www.w3.org/2000/svg\">" |
| 66 | + + "<circle cx=\"5\" cy=\"5\" r=\"4\" stroke=\"black\" stroke-width=\"1\" fill=\"red\" />" |
| 67 | + + "</svg>"; |
| 68 | +BufferedImage img = ImageIO.read(new ByteArrayInputStream(svg.getBytes(StandardCharsets.US_ASCII))); |
| 69 | +System.out.println(img); |
| 70 | +]]></source> |
65 | 71 | </subsection> |
66 | 72 | </section> |
67 | 73 | </body> |
68 | 74 | </document> |
69 | | - |
|
0 commit comments