mewebstudio / java-captcha-generator

Java Captcha Generator
MIT License
14 stars 5 forks source link

jar file #5

Closed hamedsharifi closed 7 months ago

hamedsharifi commented 8 months ago

Hello. Thanks for great work. how can I set custom font when I packaging my app to a jar file? I get "error in loading custom fonts".

mewebstudio commented 8 months ago

Hi, Have you tried installing the fonts in the src/main/resources directory in your application?

DJ45X commented 7 months ago

I am also getting the error com.mewebstudio.captcha.exception.FontLoadException: Load custom fonts failed!. I do have my font in src/main/resources/fonts/zxx-bold-regular.ttf.

DJ45X commented 7 months ago

Hello. Thanks for great work. how can I set custom font when I packaging my app to a jar file? I get "error in loading custom fonts".

After a few hours of tinkering, I have figured out that the path you provide to your font is very important. My app is running in a docker. I realized that since my docker base image uses alpine, it wouldn't have system fonts. So I added into my dockerfile to copy my custom font to /usr/share/fonts and used that path in my code. This worked perfectly!

If you aren't using docker, check your paths and be mindful of your system environment.

hamedsharifi commented 7 months ago

Thank you for your reply. I modified the source to feeding custom fonts as input streams so this way I don't worrying about copying fonts to the container.

mewebstudio commented 7 months ago

Thank you for your reply. I modified the source to feeding custom fonts as input streams so this way I don't worrying about copying fonts to the container.

Thank you for the feedback. This will be the solution for many people.