Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function optimizeImageAsync(
projectRoot: string,
inputPath: string,
quality: number
): Promise {
console.log(`\u203A Checking ${chalk.reset.bold(relative(projectRoot, inputPath))}`);
const outputPath = temporary.directory();
await sharpAsync({
input: inputPath,
output: outputPath,
quality,
// https://sharp.pixelplumbing.com/en/stable/api-output/#parameters_4
adaptiveFiltering: true,
});
return join(outputPath, basename(inputPath));
}
inputPath: string,
mimeType: string,
width: number,
height: number,
fit: ResizeMode = 'contain',
background: string
): Promise {
if (!(await isAvailableAsync())) {
return await jimpResize(inputPath, mimeType, width, height, fit, background);
}
const format = ensureValidMimeType(mimeType.split('/')[1]);
const outputPath = temporary.directory();
try {
await sharpAsync(
{
input: inputPath,
output: outputPath,
format,
},
[
{
operation: 'flatten',
background,
},
{
operation: 'resize',
width,
height,
fit,
background,
export async function optimizeImageAsync(inputPath: string, quality: number): Promise {
logger.global.info(`Optimizing ${inputPath}`);
const outputPath = temporary.directory();
await sharpAsync({
input: inputPath,
output: outputPath,
quality,
});
return path.join(outputPath, path.basename(inputPath));
}