Skip to content

Commit

Permalink
feat: allow deprecated formatQuality with logged warning
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Reed <nathreed@gmail.com>
  • Loading branch information
nathreed committed Jul 31, 2024
1 parent a436a67 commit c5895d9
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/serve_rendered.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,15 @@ const respondImage = (
image.composite(composites);
}

// Legacy formatQuality is deprecated but still works
const formatQualities = options.formatQuality || {};
if (Object.keys(formatQualities).length !== 0) {
console.log(
'WARNING: The formatQuality option is deprecated and has been replaced with formatOptions. Please see the documentation. The values from formatQuality will be used if a quality setting is not provided via formatOptions.',
);
}
const formatQuality = formatQualities[format];

const formatOptions = (options.formatOptions || {})[format] || {};

if (format === 'png') {
Expand All @@ -517,9 +526,9 @@ const respondImage = (
dither: formatOptions.dither,
});
} else if (format === 'jpeg') {
image.jpeg({ quality: formatOptions.quality || 80 });
image.jpeg({ quality: formatOptions.quality || formatQuality || 80 });
} else if (format === 'webp') {
image.webp({ quality: formatOptions.quality || 90 });
image.webp({ quality: formatOptions.quality || formatQuality || 90 });
}
image.toBuffer((err, buffer, info) => {
if (!buffer) {
Expand Down

0 comments on commit c5895d9

Please sign in to comment.