function renderImage(canvas, scale) {
const context = canvas.getContext('2d');
const canvasSize = canvas.clientWidth;
canvas.width = canvasSize;
canvas.height = canvasSize;
const ratio = (10 + scale) / 10;
const scaledImageWidth = image.width * ratio;
const scaledImageHeight = image.height * ratio;
const startX = (canvas.clientWidth - scaledImageWidth) / 2;
const startY = (canvas.clientHeight - scaledImageHeight) / 2;
context.drawImage(
image,
0, 0,
image.width, image.height,
startX, startY,
scaledImageWidth, scaledImageWidth
);
}
export const getBase64 = file => new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onerror = error => reject(error);
reader.readAsDataURL(file);
});
async sendFile() {
const b64Image = this.canvas.toDataURL('image/jpeg');
const u8Image = b64ToUint8Array(b64Image);
const formData = new FormData();
formData.append('file', new Blob([u8Image], { type: 'image/jpg' }));
const result = await http.post('/upload', formData);
},