Co-Authored-By: Andrew Calcutt <acalcutt@techidiots.net>
This commit is contained in:
acalcutt 2024-12-29 01:56:15 -05:00
parent 8dd927efe5
commit b72f662106

View file

@ -133,23 +133,31 @@ function createEmptyResponse(format, color, callback) {
} }
// create an "empty" response image // create an "empty" response image
color = new Color(color); try {
const array = color.array(); color = new Color(color);
const channels = array.length === 4 && format !== 'jpeg' ? 4 : 3; const array = color.array();
sharp(Buffer.from(array), { const channels = array.length === 4 && format !== 'jpeg' ? 4 : 3;
raw: { sharp(Buffer.from(array), {
width: 1, raw: {
height: 1, width: 1,
channels, height: 1,
}, channels,
}) },
.toFormat(format) })
.toBuffer((err, buffer, info) => { .toFormat(format)
if (!err) { .toBuffer((err, buffer, info) => {
if (err) {
console.error('Error creating image with Sharp:', err);
callback(err, null);
return;
}
cachedEmptyResponses[cacheKey] = buffer; cachedEmptyResponses[cacheKey] = buffer;
} callback(null, { data: buffer });
callback(null, { data: buffer }); });
}); } catch (error) {
console.error('Error during image processing setup:', error);
callback(error, null);
}
} }
/** /**