mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-14 01:15:51 +08:00
### What problem does this PR solve? Feat: Translate comments of file-util.ts to English #3749 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
parent
ea8a59d0b0
commit
fadbe23bfe
@ -5,20 +5,20 @@ export const transformFile2Base64 = (val: any): Promise<any> => {
|
|||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.readAsDataURL(val);
|
reader.readAsDataURL(val);
|
||||||
reader.onload = (): void => {
|
reader.onload = (): void => {
|
||||||
// 创建图片对象
|
// Create image object
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.src = reader.result as string;
|
img.src = reader.result as string;
|
||||||
|
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
// 创建canvas
|
// Create canvas
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
// 计算压缩后的尺寸,最大宽高设为800px
|
// Calculate compressed dimensions, set max width/height to 800px
|
||||||
let width = img.width;
|
let width = img.width;
|
||||||
let height = img.height;
|
let height = img.height;
|
||||||
const maxSize = 100;
|
const maxSize = 100;
|
||||||
|
|
||||||
if (width > height && width > maxSize) {
|
if (width > height && width > maxSize) {
|
||||||
height = (height * maxSize) / width;
|
height = (height * maxSize) / width;
|
||||||
width = maxSize;
|
width = maxSize;
|
||||||
@ -26,19 +26,19 @@ export const transformFile2Base64 = (val: any): Promise<any> => {
|
|||||||
width = (width * maxSize) / height;
|
width = (width * maxSize) / height;
|
||||||
height = maxSize;
|
height = maxSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置canvas尺寸
|
// Set canvas dimensions
|
||||||
canvas.width = width;
|
canvas.width = width;
|
||||||
canvas.height = height;
|
canvas.height = height;
|
||||||
|
|
||||||
// 绘制图片
|
// Draw image
|
||||||
ctx?.drawImage(img, 0, 0, width, height);
|
ctx?.drawImage(img, 0, 0, width, height);
|
||||||
|
|
||||||
// 转换为base64,保持原始格式和透明度
|
// Convert to base64, maintain original format and transparency
|
||||||
const compressedBase64 = canvas.toDataURL('image/png');
|
const compressedBase64 = canvas.toDataURL('image/png');
|
||||||
resolve(compressedBase64);
|
resolve(compressedBase64);
|
||||||
};
|
};
|
||||||
|
|
||||||
img.onerror = reject;
|
img.onerror = reject;
|
||||||
};
|
};
|
||||||
reader.onerror = reject;
|
reader.onerror = reject;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user