0

I am testing Jimp.js for image manipulation (using React with react-scripts, npm: 6.14.4, node: v12.16.3)

Everything is going well except writing text on a loaded image

import Jimp from 'jimp'

Jimp.read(image)
      .then(image => {
        console.log('image loaded', image)
        Jimp.loadFont(Jimp.FONT_SANS_32_WHITE).then(font => {
          console.log('font loaded', font)
          image.print(font, 10, 10, 'Hello world that wraps!', 12)
          // write image
        })
      })

This throws an error "error parsing font malformed file -- no element" in browser.js of load-bmfont module line 71 and dont execute the log 'font loaded'.

Googling not help i found only 2,3 items about this, associate with using custom fonts - but i use standard font from Jimp. (Using BMFont files instead of Jimp standard fonts doesnt help)

My first thought was the error ocured in a React App in the browser, so i write a Jest test to see if its work without browser context but it fail just like that.

Got any ideas?

ahuegle
  • 21
  • 4

1 Answers1

0

Solved... I'm using the React App within a Java Web Framework in a JSP File.

Jimp.loadFont(Jimp.FONT_SANS_32_WHITE)

search the font in a path that doesn`t exist for the webapp.

Moving the font files to a reachable path with context root

Jimp.loadFont(`${CONTEXT_ROOT}/foo/bar/font.font`) works.
ahuegle
  • 21
  • 4