PNG
Encyclopedia : P : PN : PNG : PNG
- For other uses, see (disambiguation)}}}.
PNG files nearly always use the file extension PNG or png and are assigned the MIME media type image/png (approved on October 14 1996).
| Byte(s) | Purpose |
|---|---|
| 89 | Has the high bit set to detect transmission systems that do not support 8 bit data and to reduce the chance that a text file is mistakenly interpreted as a PNG. |
| 50 4E 47 | In ASCII, the letters "PNG", allowing a human to identify the format easily if it is viewed in a text editor. |
| 0D 0A | A DOS style line ending (CRLF) to detect DOS-UNIX line ending conversion of the data. |
| 1A | A byte that stops display of the file under DOS |
| 0A | A unix line ending (LF) to detect UNIX-DOS line ending conversion. |
The chunks each have a header specifying their size and type. This is immediately followed by the actual data, and then the checksum of the data. Chunks are given a 4 letter case sensitive name. The case of the different letters in the name provides the decoder with some information on the nature of chunks it does not recognise.
The case of the first letter indicates if the Chunk is essential or not. If the first letter is uppercase, the chunk is essential. If not, the chunk is ancillary. Essential chunks contain information that is necessary to read the file. If a decoder encounters an essential chunk it does not recognise, it must abort reading the file.
The case of the second letter indicates if the chunk is "public" (either in the specification or the registry of special purpose public chunks) or "private" (not standardised). Uppercase is public and lowercase is private. This ensures that public and private chunk names can never conflict with each other.
The third letter must be uppercase to conform to the PNG specification. It is reserved for future expansion.
The case of the fourth letter indicates if a chunk is safe to copy by editors that do not recognise it. If lowercase the chunk may be safely copied regardless of the extent of modifications to the file. If uppercase it may only be copied if the modifications have not touched any critical chunks.
The number of channels will depend on whether the image is greyscale or color and whether it has an alpha channel. PNG allows the following combinations of channels:
| Type | Bit depth per channel | ||||
|---|---|---|---|---|---|
| 1 | 2 | 4 | 8 | 16 | |
| indexed (color type 3) | style="background: #ddffdd" | | style="background: #ddffdd" | | style="background: #ddffdd" | | style="background: #ddffdd" | |
Northern Ontario |
| greyscale (color type 0) | style="background: #ddffdd" | | style="background: #ddffdd" | | style="background: #ddffdd" | | style="background: #ddffdd" | | style="background: #ddffdd" | |
| greyscale & alpha (color type 4) |
Northern Ontario |
Northern Ontario |
Northern Ontario | style="background: #ddffdd" | | style="background: #ddffdd" | |
| truecolor (RGB - color type 2) |
Northern Ontario |
Northern Ontario |
Northern Ontario | style="background: #ddffdd" | | style="background: #ddffdd" | |
| truecolor & alpha (RGBA - color type 6) |
Northern Ontario |
Northern Ontario |
Northern Ontario | style="background: #ddffdd" | | style="background: #ddffdd" | |
With indexed color images, the palette is always stored at a depth of 8 bits per channel. The palette must not have more entries than the image bitdepth allows for but it may have fewer (so if an image for example only uses 90 colors there is no need to have palette entries for all 256).
Indexed color PNGs are allowed to have 1, 2, 4 or 8 bits per pixel by the standard; greyscale images with no alpha channel allow for 1, 2, 4, 8 or 16 bits per pixel. Everything else uses a bitdepth per channel of either 8 or 16. The combinations this allows are given in the table above. The standard requires that decoders can read all supported color formats but many image editors can only produce a small subset of them.
The scanning of pixel values for binary transparency is supposed to be performed before any color reduction to avoid pixels becoming unintentionally transparent. This is most likely to pose an issue for systems that can decode 16 bits per channel images (as they must to be compliant with the specification) but only output at 8 bits per channel (the norm for all but the highest end systems).
Macromedia Fireworks uses PNG as its native file format but by default also stores metadata for layers, animation, text and effects. Such files should not be distributed directly. Fireworks can instead export as an optimised PNG without the extra metadata for use on webpages etc.[link]
Other popular graphics programs which support the PNG format include Adobe Photoshop, The GIMP and GraphicConverter. Programs that support PNG and are bundled with popular operating systems include Microsoft's Paint and Apple's iPhoto.
Some image processing programs have PNG compression problems, mainly related to lack of full implementation of the PNG compressor library:
Despite campaigns such as "burn all gifs" [link], tools such as gif2png [link], calls by the Free Software Foundation, and influential writers, PNG adoption on websites has been fairly slow.
GIF is still more widely used than PNG, partially due to misconceptions but also for several real reasons:
There are also a number of methods using DirectX functions in style sheets and HTML that can make Internet Explorer display full transparency data in PNG images on web pages.
Internet Explorer also renders PNGs in a slightly incorrect color gamut. If a GIF and PNG image of several colors are placed side-by-side on a page, a user can often see a slight difference in color. While accurate color can never be guaranteed due to monitor and other computer differences among users, it can cause difficulty to web designers attempting to use several image formats on a page where color matching is important.
Generally, PNG files created by a decent encoder and without unwanted metadata should be smaller than the identical image encoded in GIF format. However, PNG gives the image creator far more flexibility than GIF and care needs to be taken to avoid PNG files that are needlessly large.
As GIF is limited to 256 colors, many image editors will automatically reduce the color depth when saving an image in GIF format. Often when people save the same truecolor image as PNG and GIF, they see that the GIF is smaller, and do not realise it is possible to create a 256 color PNG that has identical quality to the GIF with a smaller file size. This leads to the misconception that PNG files are larger than equivalent GIF files.
Some versions of Adobe Photoshop and CorelDRAW have poor PNG output support, further fuelling the idea that PNG is larger than GIF. Many graphics programs (and even Apple's Preview software) save PNGs with large amounts of metadata and color-correction data that's generally unnecessary. Unoptimized PNG files from Macromedia Fireworks are also notorious for this.
Various tools are available for optimizing PNG files. OptiPNG and pngcrush are both open-source software optimizers that run from a Unix command line or a Windows Command Prompt, and are very effective at reducing the size of PNG files.
Other tools such as AdvanceCOMP and Ken Silverman's [PNGOUT] are capable of reducing the file size even further, giving the competent user the smallest file size possible for a given PNG image. The current version of IrfanView can use PNGOUT as an external plug-in, and the screenshots show PNGOUT's save options.
pngcrush and PNGOUT have the extra ability to remove all color correction data from PNG files (gamma, white balance, ICC color profile, standard RGB color profile). This often results in much smaller file sizes. The following command line options achieve this with pngcrush:
pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB InputFile.png OutputFile.png
PNG was not intended to replace the other popular web image format JPEG. See the Comparison with JPEG section below for more details on how the two formats compare.
JPEG will produce a smaller file than PNG for photographic (and photo-like) images since it uses a lossy encoding method specifically designed for photographic image data. Using PNG instead of a high-quality JPEG for such images would result in a large increase in filesize (often 5-10 times) with negligible gain in quality.
PNG is a better choice than JPEG for storing images that contain text, line art, or other images with sharp transitions that do not transform well into the frequency domain. Where an image contains both sharp transitions and photographic parts a choice must be made between the large but sharp PNG and a small JPEG with artifacts around sharp transitions.
JPEG is a poor choice for storing images that require further editing as it suffers from generation loss, whereas lossless formats do not. This makes PNG useful for saving temporary photographs that require successive editing. When the photograph is ready to be distributed, it can then be saved as a JPEG, and this limits the generation loss to just one generation. That said, PNG does not support Exif image data from sources such as digital cameras, which makes it problematic for use amongst amateur and especially professional photographers. TIFF does support it as a lossless format, but is much larger in file size for an equivalent image.
The most common general-purpose lossless compression algorithm used with TIFF is LZW, which is inferior to PNG and suffers from the same patent issues that GIF does. There is an option to use the same compression algorithm with TIFF as PNG uses, but it is not supported by many proprietary programs. TIFF also offers special-purpose lossless compression algorithms like CCITT Group IV, which can compress black and white text better than PNG's compression algorithm.
From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.