Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ import xcursorHandler from "./xcursor.ts";
import shToElfHandler from "./shToElf.ts";
import cssHandler from "./css.ts";
import TypstHandler from "./typst.ts";
import kraHandler from "./kra.ts";
import krzHandler from "./krz.ts";
import BRARCHIVEHandler from "./brarchive.ts";
import wasiRunnerHandler from "./wasiRunner.ts";
import clangWasiHandler from "./clang-wasi.ts";
Expand Down Expand Up @@ -157,6 +159,8 @@ try { handlers.push(new xcursorHandler()) } catch (_) { };
try { handlers.push(new shToElfHandler()) } catch (_) { };
try { handlers.push(new cssHandler()) } catch (_) { };
try { handlers.push(new TypstHandler()) } catch (_) { };
try { handlers.push(new kraHandler()) } catch (_) { };
try { handlers.push(new krzHandler()) } catch (_) { };
try { handlers.push(new BRARCHIVEHandler()) } catch (_) { };
try { handlers.push(new wasiRunnerHandler()) } catch (_) { };
try { handlers.push(new clangWasiHandler()) } catch (_) { };
Expand Down
66 changes: 66 additions & 0 deletions src/handlers/kra.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import type { FileData, FileFormat, FormatHandler } from "../FormatHandler.ts";
import CommonFormats from "src/CommonFormats.ts";
import JSZip from "jszip";

class kraHandler implements FormatHandler {
public name: string = "kra";
public supportedFormats?: FileFormat[];
public ready: boolean = false;

async init() {
this.supportedFormats = [
CommonFormats.PNG.builder("png").allowFrom(false).allowTo(true),

{
name: "Krita Raster Archive (KRA)",
format: "kra",
extension: "kra",
mime: "application/x-krita",
from: true,
to: false,
internal: "kra",
category: ["archive"],
lossless: false,
},
];
this.ready = true;
}

async doConvert(
inputFiles: FileData[],
inputFormat: FileFormat,
outputFormat: FileFormat,
): Promise<FileData[]> {
const outputFiles: FileData[] = [];
if (inputFormat.format == "kra" && outputFormat.format == "png") {
for (const inputFile of inputFiles) {
const zip = new JSZip();
const zipContent = await zip.loadAsync(inputFile.bytes);
let imageFile;

try {
imageFile = zipContent.file("mergedimage.png");

if (!imageFile) {
throw new Error();
}
} catch {
imageFile = zipContent.file("preview.png");

if (!imageFile) {
throw new Error("Could not find image in KRA file");
}
}
const imageData = await imageFile.async("uint8array");
outputFiles.push({
name: inputFile.name.replace(/\.kra$/, ".png"),
bytes: imageData,
});
}
}

return outputFiles;
}
}

export default kraHandler;
57 changes: 57 additions & 0 deletions src/handlers/krz.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type { FileData, FileFormat, FormatHandler } from "../FormatHandler.ts";
import CommonFormats from "src/CommonFormats.ts";
import JSZip from "jszip";

class krzHandler implements FormatHandler {
public name: string = "krz";
public supportedFormats?: FileFormat[];
public ready: boolean = false;

async init() {
this.supportedFormats = [
CommonFormats.PNG.builder("png").allowFrom(false).allowTo(true),

{
name: "Krita Raster Archive (krz)",
format: "krz",
extension: "krz",
mime: "application/x-krita",
from: true,
to: false,
internal: "krz",
category: ["archive"],
lossless: false,
},
];
this.ready = true;
}

async doConvert(
inputFiles: FileData[],
inputFormat: FileFormat,
outputFormat: FileFormat,
): Promise<FileData[]> {
const outputFiles: FileData[] = [];
if (inputFormat.format == "krz" && outputFormat.format == "png") {
for (const inputFile of inputFiles) {
const zip = new JSZip();
const zipContent = await zip.loadAsync(inputFile.bytes);
const imageFile = zipContent.file("preview.png");

if (!imageFile) {
throw new Error("Could not find image in krz file");
}

const imageData = await imageFile.async("uint8array");
outputFiles.push({
name: inputFile.name.replace(/\.krz$/, ".png"),
bytes: imageData,
});
}
}

return outputFiles;
}
}

export default krzHandler;