Automattic / Automattic/node-canvas

Low quality JPEG output causes warning on STDERR (v2.3.1)

Open
#1,359 6 comments 0 reactions 0 assignees View on GitHub
Bug
Dominant language
JavaScript
Stars
10.7k
Forks
1.2k
Avg merge
4d 8h
Merged PRs (30d)
1

Description

When producing a JPEG with a lower quality setting (e.g. `0.1`) on node-canvas v2.3.1, a warning of some kind is emitted to STDERR. The warning text is `Caution: quantization tables are too coarse for baseline JPEG`. I am seeing this on both macOS and Linux using node-canvas v2.3.1.

**macOS Sierra**
```
Caution: quantization tables are too coarse for baseline JPEG
Tests performed on Node.js v10.14.1, node-canvas v2.3.1 (Darwin darwin x64 16.7.0, 16384 MB RAM)
```

**AWS Linux***
```
Caution: quantization tables are too coarse for baseline JPEG
Tests performed on Node.js v10.9.0, node-canvas v2.3.1 (Linux linux x64 4.14.62-65.117.amzn1.x86_64, 1957 MB RAM)
```

## Steps to Reproduce

```js
// node-canvas v2.x jpeg low quality test
const { createCanvas } = require('canvas');

var canvas = createCanvas( 640, 480 );
var context = canvas.getContext('2d');

var buf = canvas.toBuffer('image/jpeg', { quality: 0.1 } );

const os = require('os');
console.log(
"Tests performed on Node.js " + process.version +
", node-canvas v" + require('canvas/package').version +
" (" + os.type() + " " + os.platform() + " " + os.arch() + " " +
os.release() + ", " + Math.floor( os.totalmem() / 1024 / 1024 ) + " MB RAM)"
);
```

I understand this may be a legitimate libcairo or libjpeg warning, but it really shouldn't be emitted to STDERR. That IO pipe may be in use for other things. Ideally this could be emitted internally, possibly using an EventEmitter, so people can listen for it if they want to:

```js
// just an idea...
canvas.on('warning', function(msg) {
console.log("Caught warning: " + msg);
});
```

## Your Environment

Shown above as part of script output.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the provided Node.js reproduction using canvas.toBuffer('image/jpeg', { quality: 0.1 }) and confirm when the libjpeg warning reaches STDERR on the reported platforms. Trace the JPEG encoding and warning-handling path, then verify that low-quality output no longer writes this warning directly to STDERR while the issue's requested warning behavior remains testable.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.