Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
number,
number,
number,
number,
][] = [
[1, 0, 0, 1, 0, 0],
[-1, 0, 0, 1, width, 0],
[-1, 0, 0, -1, width, height],
[1, 0, 0, -1, 0, height],
[0, 1, 1, 0, 0, 0],
[0, 1, -1, 0, height, 0],
[0, -1, -1, 0, height, width],
[0, -1, 1, 0, 0, width],
];
pica()
.resize(img, canvas)
.then(() => {
let canvas2: HTMLCanvasElement;
if (o === 1) {
canvas2 = canvas;
} else {
canvas2 = document.createElement('canvas');
const ctx = canvas2.getContext('2d');
if (!ctx) {
throw new Error('context is null');
}
canvas2.width = o > 4 ? height : width;
canvas2.height = o > 4 ? width : height;
ctx.transform(...transformations[o - 1]);
ctx.drawImage(canvas, 0, 0);
}
export default async function resizeImage(src, el, targetDimensions) {
const pica = Pica();
const from = document.createElement('canvas');
const fromContext = from.getContext('2d');
const to = document.createElement('canvas');
const fromImage = new Image();
fromImage.src = src;
const stats = await getImageStats(fromImage);
const newDimensions = getNewDimensions(stats, targetDimensions);
from.width = stats.width;
from.height = stats.height;
to.height = newDimensions.height;
to.width = newDimensions.width;
fromContext.drawImage(fromImage, 0, 0);