File tree 2 files changed +12
-3
lines changed
2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -171,7 +171,7 @@ var stream = canvas.jpegStream({
171
171
bufsize: 4096 // output buffer size in bytes, default: 4096
172
172
, quality: 75 // JPEG quality (0-100) default: 75
173
173
, progressive: false // true for progressive compression, default: false
174
- , disableChromaSubsampling : false // true to disable 2x2 subsampling of the chroma components, default: false
174
+ , chromaSubsampling : true // false to disable 2x2 subsampling of the chroma components, default: true
175
175
});
176
176
```
177
177
Original file line number Diff line number Diff line change @@ -90,12 +90,21 @@ Canvas.prototype.createJPEGStream = function(options){
90
90
// Don't allow the buffer size to exceed the size of the canvas (#674)
91
91
var maxBufSize = this . width * this . height * 4 ;
92
92
var clampedBufSize = Math . min ( options . bufsize || 4096 , maxBufSize ) ;
93
+ var chromaFactor ;
94
+ if ( typeof options . chromaSubsampling === "number" ) {
95
+ // libjpeg-turbo seems to complain about values above 2, but hopefully this
96
+ // can be supported in the future. For now 1 and 2 are valid.
97
+ // https://github.com/Automattic/node-canvas/pull/1092#issuecomment-366558028
98
+ chromaFactor = options . chromaSubsampling ;
99
+ } else {
100
+ chromaFactor = options . chromaSubsampling === false ? 1 : 2 ;
101
+ }
93
102
return new JPEGStream ( this , {
94
103
bufsize : clampedBufSize
95
104
, quality : options . quality || 75
96
105
, progressive : options . progressive || false
97
- , chromaHSampFactor : options . disableChromaSubsampling ? 1 : 2
98
- , chromaVSampFactor : options . disableChromaSubsampling ? 1 : 2
106
+ , chromaHSampFactor : chromaFactor
107
+ , chromaVSampFactor : chromaFactor
99
108
} ) ;
100
109
} ;
101
110
You can’t perform that action at this time.
0 commit comments