Hello. We are using sharp in our project for converting large png images to small resized jpeg images. It was working fine with the version 0.16.2 but on upgrading it to the latest version 0.18.1, it is throwing a Unable to parse color from object {"r":255,"g":255,"b":255,"a":0} error.
We are using it in this manner.
sharp(dir + '/sponsors/' + image)
.resize(150, 80)
.background({r: 255, g: 255, b: 255, a: 0})
.embed()
.toFile(dir + '/sponsors/' + image + '.new', (err) => {
if(err) {
console.log(image + ' Can not be converted');
console.log(err);
trial(null);
return 0;
}
fs.rename(dir + '/sponsors/' + image + '.new' , dir + '/sponsors/' + image , function(err) {
if ( err ) {
console.log('ERROR: ' + err);
}
trial(null);
});
});
This is the error which gets thrown:
Error: Unable to parse color from object: {"r":255,"g":255,"b":255,"a":0}
at Object.Color (/home/princu/fakeRepo/open-event-webapp/node_modules/color/index.js:87:10)
at Color (/home/princu/fakeRepo/open-event-webapp/node_modules/color/index.js:28:10)
at Sharp.background (/home/princu/fakeRepo/open-event-webapp/node_modules/sharp/lib/colour.js:31:18)
at /home/princu/fakeRepo/open-event-webapp/src/backend/dist.js:144:10
at /home/princu/fakeRepo/open-event-webapp/node_modules/async/dist/async.js:3060:16
at eachOfArrayLike (/home/princu/fakeRepo/open-event-webapp/node_modules/async/dist/async.js:1003:9)
at eachOf (/home/princu/fakeRepo/open-event-webapp/node_modules/async/dist/async.js:1051:5)
at Object.eachLimit (/home/princu/fakeRepo/open-event-webapp/node_modules/async/dist/async.js:3122:5)
at /home/princu/fakeRepo/open-event-webapp/src/backend/dist.js:141:11
at go$readdir$cb (/home/princu/fakeRepo/open-event-webapp/node_modules/graceful-fs/graceful-fs.js:149:14)
at FSReqWrap.oncomplete (fs.js:123:15)
Any idea why this error is getting thrown? Any help will be appreciated. Thanks for building such a great library. Have a nice day.!!
Hello, you'll need to use alpha for the transparency channel. a used to be accepted by older versions of the color dependency, but this now refers to the A chroma channel of LAB.
- {r: 255, g: 255, b: 255, a: 0}
+ {r: 255, g: 255, b: 255, alpha: 0}
That fixed the error. Thank you so much for helping and sorry for bugging with a trivial query. Have a nice day :slightly_smiling_face:
Most helpful comment
That fixed the error. Thank you so much for helping and sorry for bugging with a trivial query. Have a nice day :slightly_smiling_face: