Skip to content

Commit

Permalink
try to fix #1411
Browse files Browse the repository at this point in the history
Co-Authored-By: Andrew Calcutt <[email protected]>
  • Loading branch information
acalcutt committed Dec 29, 2024
1 parent 8dd927e commit b72f662
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/serve_rendered.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,31 @@ function createEmptyResponse(format, color, callback) {
}

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

/**
Expand Down

0 comments on commit b72f662

Please sign in to comment.