Closed av01d closed 3 months ago
Never mind, got it. It only works with ttf-fonts you load by url. In the exampe below, I use helvetica.ttf
.
worker.js:
import createModule from "https://unpkg.com/@jspawn/imagemagick-wasm/magick.mjs";
(async () => {
const magick = await createModule({
// Tell Emscripten where the WASM file is located.
locateFile: () => "https://unpkg.com/@jspawn/imagemagick-wasm/magick.wasm",
});
// Use `FS.createLazyFile` to create a file which reads from a URL.
magick.FS.createLazyFile('/', 'sample.jpg', 'sample.jpg', true, false);
// Read the TTF font
magick.FS.createLazyFile('/', 'helvetica.ttf', 'helvetica.ttf', true, false);
magick.callMain([
'sample.jpg',
'-pointsize',
'60',
'-gravity',
'center',
'-font',
'helvetica.ttf', // Must match filename used in createLazyFile call above
'-annotate',
'+0+0',
'I love my mom',
'out.png'
]);
const pngBuf = magick.FS.readFile("out.png");
const pngBlob = new Blob([pngBuf], { type: "image/png" });
// Send to main for a preview.
postMessage(pngBlob);
})();
I am trying to draw some text on an image using imagemagick-wasm. I found an example in your
tests
directory, which does not work in a browser (I assume it does function in node).results in:
results in
Could you provide a browser example for drawing text? Ideally one with the default
helvetica
font and one with a.ttf
font. Thanks!