16

Is there a file format limit to the PNG pixel size?

I am trying to visualize a 30.000x30.000 pixels PNG image with Firefox, but I get an error. The image opens correcly in Preview.app, although very slowly. The file size is not big, just around 3 MiB (1 bit black/white image). I am wondering if there's a technical file-format reason for this.

Stefano Borini
  • 138,652
  • 96
  • 297
  • 431
  • 1
    Hmm, limit to PNG--computer related. Limit to PNG in Firefox--Superuser. –  Nov 05 '10 at 19:46
  • @Will I think it's computer related. I'd like to know if there's a limit in the fileformat first. Now, I can check by myself but since there's no such question and I am a good guy, I ask and add a bit more knowledge to SO. It could be, say, the standard is a limit 16K x 16K. I get the error because firefox respects it and Preview.app does not. – Stefano Borini Nov 05 '10 at 19:51
  • the first definitely is, the second is a SuperUser question... No worries, I didn't vote to close! –  Nov 05 '10 at 19:56
  • 1
    QGIS (qgis.org) is a good option for viewing the file (it won't try to load the whole thing into memory) – AndrewHarvey Aug 18 '17 at 00:10

2 Answers2

12

A naive implementation of resizing would require the image to be blown up to 2.7GB in size before it is displayed. This would clearly be too large for a normal 32-bit program to handle.

The PNG specification doesn't appear to place any limits on the width and height of an image; these are 4 byte unsigned integers, which could be up to 4294967295. http://www.libpng.org/pub/png/spec/iso/index-object.html#11IHDR

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • 34
    Actually, your statement about image size limits is incorrect. PNG doesn't technically use 32-bit unsigned integers; it uses 31-bit unsigned integers padded with an extra zero bit. This was done to accommodate languages which don't have unsigned integer types. The upper limit on image width or height is thus 2^31-1 or 2,147,483,647. – DK. Mar 20 '11 at 03:53
  • 1
    My tests on Windows shows that FFox use the DIB api, which has a maximum size of 4096 x 4096. This may have changed with Windows 10 - but the moment you go beyond this browsers start to fail. Some may work on windows but fail on linux etc. etc. – Jon Lennart Aasenden Apr 23 '17 at 08:05
  • 1
    @JonLennartAasenden that should be an answer, not a comment. Good for you to draw a distinction between the limit imposed by the spec and more practical limits. – Mark Ransom Apr 23 '17 at 14:37
  • Thanks for the confidense, but since this may have changed (although i doubt it on windows at least) it may not be true for mac. All systems have a DIB (device independent bitmap) system - but their limitations vary from OS to OS. – Jon Lennart Aasenden Apr 29 '17 at 22:05
  • 1
    A little off-topic, but relevant. The Deflate algorithm used in PNG may impose the actual limit of the format. The JPEG standard is 65,535 pixels and the .NET System.Windows.Imaging PNG Encoder uses the same limit. I know this empirically from experimentation. FireFox is able to display a 65,100x10,200 image, but *very* poorly. Chrome, IE, and New Edge (Chromium based) don't display at all. Lesson learned: Browsers suck - use a purpose-built tool – B H Apr 07 '21 at 21:11
3

That is an odd image, but I am sure there is a reason to have such a huge image.

I can't really address the size limit, but I can address a way to get around it. Create a set of tiles of some size, and then as the user scrolls, bring tiles into view using CSS to position them correctly. You might even be able to get away with bringing up all the tiles at once, with a slew of smaller images.

But I am curious, what is the application that needs such a huge image displayed without scaling out?

Erick

Erick T
  • 7,009
  • 9
  • 50
  • 85
  • I'm rendering the mandelbrot parameter space, see my blog. Took 10 days of computation. – Stefano Borini Nov 05 '10 at 19:54
  • 1
    @Stefano: The standard says size is 32 bit unsigned integer so the theoretical limit would be somewhere around 4 billion pixels (nine zeros) x and y. As mentioned by Mark Ransom, a straightforward implementation of PNG would require almost 3GB to render your 30k by 30k pixel image. Firefox probably errored out when it couldn't allocate enough memory but I'm not really sure since I don't know exactly how firefox renders PNGs. – slebetman Nov 05 '10 at 20:16
  • 1
    This reeks of a case for SVG.. anytime your file size gets that big it's time to think of vector vs raster.. SVG can draw many complex shapes with fractals and sprites too.. the size is infinite so you could draw it and scale it up to be the size of a billboard with zooming in and no loss of quality. – Tim Davis May 18 '20 at 06:02
  • @TimDavis not everything can be rendered into SVG (especially 3D objects with lighting maps etc.) and e.g. for satellite imagery extreme sizes are pretty commonplace too. – CoolKoon Aug 05 '20 at 12:23