Saturday, November 17, 2012

Calculating Image (PNG) Size

There are a couple of APIs that create an image, usually from a PDF.  The formula below helps you determine the size of the resulting image.  This is important as you might be dealing with a restricted Activation Key that protects your billing amount.  Bottom line- use your head and don't create images larger than you actually need.

The formula:
PNG Size = N*P*S^2
N=Number of pages (typically N=1 if you are creating an image of a single page).
P=Page size which depends on what is in the page (how much content).  We'll use the maximum possible which is:
P=WxHxC(bytes)=Width of page in pixels x Height in pixels x C (C=1 for grayscale, 4 for color) in bytes at scale=1.0

A normal 8.5x11 page at scale = 1.0 (100%) is 611 pixels by 791 pixels.  So P = 611x791x4=1,993,204 or about 2MB for color or about 472KB for grayscale.

So the biggest a PNG page at scale 1.0 will be is 2MB.  The max allowed scale is 3.0.
At this level, the max PNG will be 1*2MB*9=18MB!

Since most activation keys are limited to 6MB, your max scale would be:
S=sqrt(6MB/2MB)=sqrt(3MB)=1.73.

Conclusion- make sure your key has at least 2MB max upload and think twice about going over 1.0 for scale.

Credits:
Thanks to SoftServe for providing the above information

Here is an example API that such conversation applies to:
https://secure.cloudpiston.com/cpal/cp-api/console/PdfFile.html#80AD098E019FA7775F8AD0487D5424DD
   

No comments:

Post a Comment