Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
PNG
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== File size and optimization software == <!-- Deleted image removed: [[File:PNGOUT plugin.png|frame|right|Screenshots of the Save Options for the [[PNGOUT]] plugin which is included in the [[IrfanView]] image converter. The screenshots show the default settings.|{{Deletable image-caption|1=Sunday, 27 April 2008|date=May 2012}}]] --> PNG file size can vary significantly depending on how it is encoded and compressed; this is discussed and a number of tips are given in ''PNG: The Definitive Guide.''<ref name="pngcf" /> === Compared to GIF === Compared to [[GIF]] files, a PNG file with the same information (256 colors, no ancillary chunks/metadata), compressed by an effective compressor is normally smaller than a GIF image. Depending on the file and the compressor, PNG may range from somewhat smaller (10%) to significantly smaller (50%) to somewhat larger (5%), but is rarely significantly larger<ref name="pngcf" /> for large images. This is attributed to the performance of PNG's [[DEFLATE]] compared to GIF's [[LZW]], and because the added precompression layer of PNG's predictive filters take account of the 2-dimensional image structure to further compress files; as filtered data encodes differences between pixels, they will tend to cluster closer to 0, rather than being spread across all possible values, and thus be more easily compressed by DEFLATE. However, some versions of [[Adobe Photoshop]], [[CorelDRAW]] and [[Microsoft Paint|MS Paint]] provide poor PNG compression, creating the impression that GIF is more efficient.<ref name="pngcf" /> === File size factors === PNG files vary in size due to a number of factors: ;color depth: Color depth can range from 1 to 64 bits per pixel. ;ancillary chunks: PNG supports metadataโthis may be useful for editing, but unnecessary for viewing, as on websites. ;interlacing: As each pass of the Adam7 algorithm is separately filtered, this can increase file size.<ref name="pngcf" /> ;filter: As a precompression stage, each line is filtered by a predictive filter, which can change from line to line. As the ultimate DEFLATE step operates on the whole image's filtered data, one cannot optimize this row-by-row; the choice of filter for each row is thus potentially very variable, though heuristics exist.<ref group="note">The filtering is used to increase the similarity to the data, hence increasing the compression ratio. However, there is theoretically no formula for similarity, nor absolute relationship between the similarity and compressor, thus unless the compression is done, one can't tell one filter set is better than another.</ref> ;compression: With additional computation, DEFLATE compressors can produce smaller files. There is thus a filesize trade-off between high color depth, maximal metadata (including color space information, together with information that does not affect display), interlacing, and speed of compression, which all yield large files, with lower color depth, fewer or no ancillary chunks, no interlacing, and tuned but computationally intensive filtering and compression. For different purposes, different trade-offs are chosen: a maximal file may be best for archiving and editing, while a stripped down file may be best for use on a website, and similarly fast but poor compression is preferred when repeatedly editing and saving a file, while slow but high compression is preferred when a file is stable: when archiving or posting. Interlacing is a trade-off: it dramatically speeds up early rendering of large files (improves latency), but may increase file size (decrease throughput) for little gain, particularly for small files.<ref name="pngcf" /> ==== Lossy PNG compression ==== Although PNG is a lossless format, PNG encoders can preprocess image data in a lossy fashion to improve PNG compression. For example, quantizing a truecolor PNG to 256 colors allows the indexed color type to be used for a likely reduction in file size.<ref>{{cite web|url=http://pngmini.com/lossypng.html|title=PNG can be a lossy format|publisher=Pngmini.com|access-date=2014-02-01}}</ref> === Image editing software === Some programs are more efficient than others when saving PNG files, this relates to implementation of the PNG compression used by the program. Many graphics programs (such as Apple's [[Preview (software)|Preview]] software) save PNGs with large amounts of [[metadata]] and color-correction data that are generally unnecessary for [[World Wide Web|Web]] viewing. Unoptimized PNG files from [[Adobe Fireworks]] are also notorious for this since they contain options to make the image editable in supported editors. Also CorelDRAW (at least version 11) sometimes produces PNGs which cannot be opened by Internet Explorer (versions 6โ8). [[Adobe Photoshop]]'s performance on PNG files has improved in the CS Suite when using the Save For Web feature (which also allows explicit PNG/8 use). Adobe's Fireworks saves larger PNG files than many programs by default. This stems from the mechanics of its ''Save'' format: the images produced by Fireworks' save function include large, private chunks, containing complete layer and vector information. This allows further lossless editing. When saved with the ''Export'' option, Fireworks' PNGs are competitive with those produced by other image editors, but are no longer editable as anything but flattened bitmaps. Fireworks is unable to save size-optimized vector-editable PNGs. Other notable examples of poor PNG compressors include: * Microsoft's Paint for Windows XP * Microsoft Picture It! Photo Premium 9 <!-- explain? --> Poor compression increases the PNG file size but does not affect the image quality or compatibility of the file with other programs. When the color depth of a [[24-bit color|truecolor]] image is reduced to an 8-bit palette (as in GIF), the resulting image data is typically much smaller. Thus a truecolor PNG is typically larger than a color-reduced GIF, although PNG could store the color-reduced version as a palettized file of comparable size. Conversely, some tools, when saving images as PNGs, automatically save them as truecolor, even if the original data use only 8-bit color, thus bloating the file unnecessarily.<ref name="pngcf" /> Both factors can lead to the misconception that PNG files are larger than equivalent GIF files. === Optimizing tools === Various tools are available for optimizing PNG files; they do this by: * (optionally) removing ancillary chunks, * reducing [[color depth]], either: ** use a palette (instead of RGB) if the image has 256 or fewer colors, ** use a smaller palette, if the image has 2, 4, or 16 colors, or ** (optionally) lossily discard some of the data in the original image, * optimizing line-by-line filter choice, and * optimizing DEFLATE compression. ==== Tool list ==== * [[pngcrush]] is the oldest of the popular PNG optimizers. It allows for multiple trials on filter selection and compression arguments, and finally chooses the smallest one. This working model is used in almost every png optimizer. * advpng and the similar advdef utility in the AdvanceCOMP package recompress the PNG IDAT. Different DEFLATE implementations are applied depending on the selected compression level, trading between speed and file size: zlib at level 1, libdeflate at level 2, [[7-zip]]'s [[LZMA]] DEFLATE at level 3, and [[zopfli]] at level 4. * [[pngout]] was made with the author's own deflater (same to the author's zip utility, kzip), while keeping all facilities of color reduction / filtering. However, pngout doesn't allow for using several trials on filters in a single run. It's suggested to use its commercial GUI version, pngoutwin, or used with a [[#Wrapper tools|wrapper]] to automate the trials or to recompress using its own deflater while keep the filter line by line.<ref name="pngoutreusefilter" group="note">Use pngout -f6 to reuse previous filter set</ref> * [[zopfli]]png was also made with its own deflater, zopfli. It has all the optimizing features pngcrush has (including automating trials) while providing a very good, but slow deflater. A simple comparison of their features is listed below. {| class="wikitable" |- ! Optimizer !! Chunk removal !! Color reduction !! Filtering !! Filter reuse<ref group="note">The tools offering such feature could act as a pure re-deflater to PNG files.</ref> !! Multiple trials on filters in a single run !! Deflater<ref group="note">[[zlib]], the reference deflate implementation, compression is suboptimal even at the maximum level. See [[Zopfli]], [[7-zip#Others|zip format in 7-zip]] and [[pngout]].</ref> |- | advpng|| Yes|| No<ref group="note">Not only does advpng not support color reduction, it also fails on images with a reduced colorspace.</ref>|| 0|| No|| N/A<ref group="note">Advpng can only apply filter 0 globally, thus it's neither yes or no, but N/A.</ref>|| (multiple) |- | advdef|| No|| No|| Reuses previous filter set|| Always|| N/A|| (multiple) |- | [[pngcrush]]|| Yes|| Yes|| 0โ4 or adaptive|| No|| Yes|| zlib |- | [[pngout]]|| Yes|| Yes|| 0โ4 or adaptive|| Yes<ref name="pngoutreusefilter" group="note"/>|| No|| kzip |- | [[zopfli]]png|| Yes|| Yes|| 0โ4 or adaptive with 2 different algorithms, or with a brute way|| Yes|| Yes|| zopfli |} Before zopflipng was available, a good way in practice to perform a png optimization is to use a combination of 2 tools in sequence for optimal compression: one which optimizes filters (and removes ancillary chunks), and one which optimizes DEFLATE. Although pngout offers both, only one type of filter can be specified in a single run, therefore it can be used with a [[#Wrapper tools|wrapper tool]] or in combination with [[pngcrush]],<ref name="pngoutreusefilter" group="note"/> acting as a re-deflater, like advdef. ==== Ancillary chunk removal ==== For removing ancillary chunks, most PNG optimization tools have the 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. For example, the following command line options achieve this with pngcrush: <code>pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB ''InputFile.png'' ''OutputFile.png''</code> ==== Filter optimization ==== pngcrush, pngout, and zopflipng all offer options applying one of the filter types 0โ4 globally (using the same filter type for all lines) or with a "pseudo filter" (numbered 5), which for each line chooses one of the filter types 0โ4 using an adaptive algorithm. Zopflipng offers 3 different adaptive method, including a brute-force search that attempts to optimize the filtering.<ref group="note">[pngcrush|pngout] -f OR zopflipng --filters</ref> pngout and zopflipng provide an option to preserve/reuse<ref name="pngoutreusefilter" group="note"/><ref group="note">zopflipng --filters=p</ref> the line-by-line filter set present in the input image. pngcrush and zopflipng provide options to try different filter strategies in a single run and choose the best. The freeware command line version of pngout doesn't offer this, but the commercial version, pngoutwin, does.<ref group="note">Pngoutwin's setting dialog for optimization offers the user a selection of filter strategies.</ref> ==== DEFLATE optimization ==== [[Zopfli]] and the [[7zip#Software development kit|LZMA SDK]] provide [[DEFLATE]] implementations that can produce higher [[Data compression ratio|compression ratio]]s than the [[zlib]] reference implementation at the cost of performance. AdvanceCOMP's <code>advpng</code> and <code>advdef</code> can use either of these libraries to re-compress PNG files. Additionally, [[PNGOUT]] contains its own [[proprietary software|proprietary]] DEFLATE implementation. <code>advpng</code> doesn't have an option to apply filters and always uses filter 0 globally (leaving the image data unfiltered); therefore it should not be used where the image benefits significantly from filtering. By contrast, <code>advdef</code> from the same package doesn't deal with PNG structure and acts only as a re-deflater, retaining any existing filter settings. === Icon optimization === Since [[icon (computing)|icons]] intended for Windows Vista and later versions may contain PNG subimages, the optimizations can be applied to them as well. At least one [[icon (computing)|icon editor]], Pixelformer, is able to perform a special optimization pass while saving [[ICO (file format)|ICO]] files, thereby reducing their sizes. [[Apple Icon Image format|Icons for macOS]] may also contain PNG subimages, yet there isn't such tool available.{{citation needed|date=November 2021}}
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
PNG
(section)
Add topic