mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-11-13 17:08:20 +00:00
fix: image decode error i18n
This commit is contained in:
+10
-2
@@ -59,6 +59,14 @@ export function unsupportedImageError(file: File): ToolError {
|
||||
});
|
||||
}
|
||||
|
||||
async function toBitmap(source: Blob | File): Promise<ImageBitmap> {
|
||||
try {
|
||||
return await createImageBitmap(source);
|
||||
} catch {
|
||||
throw new ToolError("errors.imageDecode");
|
||||
}
|
||||
}
|
||||
|
||||
async function decodeBitmap(bitmap: ImageBitmap): Promise<PixelImage> {
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = bitmap.width;
|
||||
@@ -77,7 +85,7 @@ async function decodeBitmap(bitmap: ImageBitmap): Promise<PixelImage> {
|
||||
}
|
||||
|
||||
export async function decodeFile(file: File): Promise<PixelImage> {
|
||||
const bitmap = await createImageBitmap(file);
|
||||
const bitmap = await toBitmap(file);
|
||||
try {
|
||||
return await decodeBitmap(bitmap);
|
||||
} finally {
|
||||
@@ -89,7 +97,7 @@ export async function decodeBytes(
|
||||
bytes: Uint8Array<ArrayBuffer>,
|
||||
): Promise<PixelImage> {
|
||||
const blob = new Blob([bytes]);
|
||||
const bitmap = await createImageBitmap(blob);
|
||||
const bitmap = await toBitmap(blob);
|
||||
try {
|
||||
return await decodeBitmap(bitmap);
|
||||
} finally {
|
||||
|
||||
@@ -192,6 +192,8 @@ export const en: Dict = {
|
||||
"Crop area doesn't fit: offset plus size exceeds the image bounds",
|
||||
noCanvasCtx: "Canvas 2D context is unavailable in this environment",
|
||||
badBase64: "Expected a base64 string or a data-uri of an image",
|
||||
imageDecode:
|
||||
"Can't read the image — the file is corrupted or the format is unsupported",
|
||||
qualityRange: "quality must be within 0..1",
|
||||
svgSize: "Could not determine SVG dimensions",
|
||||
svgLoad: "Failed to load SVG — check the markup",
|
||||
|
||||
@@ -193,6 +193,8 @@ export const ru: Dict = {
|
||||
"Область не помещается: смещение + размер превышают границы изображения",
|
||||
noCanvasCtx: "Canvas 2D context недоступен в этом окружении",
|
||||
badBase64: "Ожидается base64-строка или data-uri изображения",
|
||||
imageDecode:
|
||||
"Не удалось прочитать изображение — файл повреждён или формат не поддерживается",
|
||||
qualityRange: "quality должно быть в диапазоне 0..1",
|
||||
svgSize: "Не удалось определить размер SVG",
|
||||
svgLoad: "Не удалось загрузить SVG — проверьте разметку",
|
||||
|
||||
Reference in New Issue
Block a user