async function magickImage(imageurl, opts = {}) {
const {
cmd = "-rotate 30 -resize 100%",
mode = "image",
verbose = false
} = opts;
const img = await fetchImage(imageurl);
const arrayBuffer = await img.blob.arrayBuffer();
const sourceBytes = new Uint8Array(arrayBuffer);
const file = [{ name: 'input.png', content: sourceBytes }];
const commands = `convert input.png ${cmd} ${
mode === "text" ? ":txt out.txt" : "output.png"
}`;
if (verbose) console.log(performance.now(), commands);
const { outputFiles, exitCode } = await Magick.executeOne({
inputFiles: file,
commands
});
if (mode === "image") {
const imgout = new Image();
imgout.src = URL.createObjectURL(outputFiles[0].blob);
imgout.blob = outputFiles[0].blob;
return imgout;
} else if (mode === "text") {
const out = await Magick.readFileAsText(outputFiles[0]);
return out;
}
}