· via dev.to (home feed)
sharp's default PNG output drops 16-bit images to 8-bit unless rgb16 is requested
A dev.to writeup shows sharp re-encodes 16-bit PNGs as 8-bit by default, cutting one test image's green channel from 11,496 levels to 46 unless toColourspace('rgb16') is set.

What sharp does by default
A plain call to .png() in sharp, the Node.js image processing library, re-encodes 16-bit input as 8-bit output. The behavior is documented — sharp's output options state that PNG output is full colour at 8 bits per pixel by default, and that 16-bit output requires converting to the rgb16 colourspace first — but according to a November 2026 dev.to writeup, it is easy to miss because nothing in the pipeline warns you.
The author of that post found the relevant documentation paragraph only after noticing that a 10.4 MB 16-bit PNG came back from sharp as a 66 KB file.
How the test was built
Most readily available 16-bit images are actually 8-bit photos widened to 16 bits, which proves nothing about depth preservation. So the author wrote a genuine 16-bit PNG from scratch with a small Node script: a 1920 × 1280 synthetic sky with the green channel sweeping smoothly from 1,080 to 12,595 out of 65,535, plus two levels of noise. Smooth, dark gradients are precisely the content where lost precision becomes visible banding.
The numbers
sharp's metadata call confirmed the file was read as 16-bit, with a depth of ushort, yet the default re-encode produced an 8-bit PNG. Counting levels in the green channel showed what was discarded: 11,496 distinct values in the source, 46 in the output. On the middle row of the 8-bit result, the longest run of identical green values was 143 consecutive pixels — the stair-step pattern familiar from dark skies and vignettes.
Adding .toColourspace('rgb16') before .png() preserved the depth. The resulting file sizes, per the writeup:
- Source 16-bit PNG: 10,358,752 bytes
- 16-bit re-encode with rgb16: 9,605,628 bytes
- Default 8-bit PNG: 66,111 bytes, roughly 157 times smaller than the source
- 8-bit palette PNG at quality 90: 142,786 bytes
- JPEG at quality 90: 16,188 bytes; WebP at quality 90: 11,562 bytes; AVIF at quality 60: 3,142 bytes
The dramatic size gap comes from the noise: two levels of noise are real information at 16 bits and vanish at 8, letting the file compress to almost nothing.
The default hides in raw output too
The same trap affects .raw({ depth: 'ushort' }). On the 16-bit test file it returned green values with a maximum of 49 instead of 12,595, because the pipeline had already dropped to 8-bit before the raw data was read. toColourspace('rgb16') has to come first there as well — relevant to anyone using sharp for histograms, averaging or machine-learning preprocessing.
When 16 bits are worth keeping
Widening does not add information. Re-encoding an 8-bit sample photo as a 16-bit PNG grew the file by 26.7 percent, to 4,999,854 bytes from 3,944,916, with nothing new in it. The writeup's rule of thumb: keep 16 bits for sources that genuinely have them — scans, RAW exports, HDR renders, grading work — and for web delivery, convert to 8-bit deliberately, adding dither or grain first if the image has smooth gradients.
Checks for a pipeline
The author suggests reading metadata().depth, where ushort signals 16-bit input; logging the 8-bit downgrade as an explicit decision when serving images to the web; and for archival masters, writing with rgb16 and verifying the result by parsing the PNG header, since bit depth and colour type sit at fixed offsets (bytes 24 and 25) of the IHDR chunk. The final caution is to never judge an 8-bit result by file size alone — the 66 KB output looked like a success until the levels were counted.
The measurements were single runs on Node v24.22.0, sharp 0.35.4 (libvips 8.18.6, libpng 1.6.58) on an Apple M1 Pro. The author did not test real 16-bit photographs, grayscale or RGBA 16-bit variants, or TIFF output, and evaluated banding by counting levels rather than viewing the images. The post also notes that an AI assistant helped run the measurements.
Why it matters
The failure mode is silent: sharp accepts the 16-bit input, reports it correctly in metadata, and writes a much smaller file that looks like a win on any size dashboard. The cost is a visible quality regression — heavy banding in smooth gradients — that only surfaces when someone counts what survived the conversion. For pipelines that use sharp as a preprocessing step rather than a delivery step, the same default can quietly corrupt pixel data before it reaches the code that cares about it. One explicit colourspace call, plus a header check in tests, closes the gap.
- #node-js
- #image-processing
- #png
- #sharp
- #javascript