Skip to content

Commit

Permalink
Docs: clarify how to achieve 16-bit PNG output
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Feb 14, 2024
1 parent bc95531 commit 0eb5769
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
14 changes: 13 additions & 1 deletion docs/api-output.md
Expand Up @@ -367,10 +367,14 @@ const data = await sharp(input)
Use these PNG options for output image.

By default, PNG output is full colour at 8 or 16 bits per pixel.
By default, PNG output is full colour at 8 bits per pixel.

Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
Set `palette` to `true` for slower, indexed PNG output.

For 16 bits per pixel output, convert to `rgb16` via
[toColourspace](/api-colour#tocolourspace).


**Throws**:

Expand Down Expand Up @@ -405,6 +409,14 @@ const data = await sharp(input)
.png({ palette: true })
.toBuffer();
```
**Example**
```js
// Output 16 bits per pixel RGB(A)
const data = await sharp(input)
.toColourspace('rgb16')
.png()
.toBuffer();
```


## webp
Expand Down
13 changes: 12 additions & 1 deletion lib/output.js
Expand Up @@ -504,10 +504,14 @@ function jpeg (options) {
/**
* Use these PNG options for output image.
*
* By default, PNG output is full colour at 8 or 16 bits per pixel.
* By default, PNG output is full colour at 8 bits per pixel.
*
* Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
* Set `palette` to `true` for slower, indexed PNG output.
*
* For 16 bits per pixel output, convert to `rgb16` via
* {@link /api-colour#tocolourspace|toColourspace}.
*
* @example
* // Convert any input to full colour PNG output
* const data = await sharp(input)
Expand All @@ -520,6 +524,13 @@ function jpeg (options) {
* .png({ palette: true })
* .toBuffer();
*
* @example
* // Output 16 bits per pixel RGB(A)
* const data = await sharp(input)
* .toColourspace('rgb16')
* .png()
* .toBuffer();
*
* @param {Object} [options]
* @param {boolean} [options.progressive=false] - use progressive (interlace) scan
* @param {number} [options.compressionLevel=6] - zlib compression level, 0 (fastest, largest) to 9 (slowest, smallest)
Expand Down

0 comments on commit 0eb5769

Please sign in to comment.