juforg / java-html2image

Automatically exported from code.google.com/p/java-html2image
0 stars 1 forks source link

How to fix incorrect image size #8

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

So it looks like this project has essentially been abandoned - here's a tip for 
anyone else looking to use it to any great extent:

The size of the image will not be correctly regardless of whether you call the 
setSize method or not. Instead follow these steps:

1. do NOT call setSize - it makes no difference at all to picture size
2. The size should be set on the top level container in your HTML (e.g. set CSS 
width and height of top div).
3. This will make the image, on average, 1.322 scale of what you expected.
4. To solve this, simple multiply the width/height values by 0.7625f (this 
seems to be a sweet spot but you could make it more accurate still).

I use: int width = Math.round(origWidth*0.7625f); - and same again for height.

This should give you the correct height within around 3px on each axis for 
pictures less than 1024*768 in size.

Hope this helps someone, pity this library is no longer under development 
although looking at the code it uses a lot of weird tricks to force the HTML 
into an image format. 

Cheers,

Jack

Original issue reported on code.google.com by sempra...@googlemail.com on 25 Apr 2012 at 11:33