charmbracelet / freeze

Generate images of code and terminal output 📸
MIT License
3.24k stars 55 forks source link

Output blank png image when use custom font family in windows #80

Open lrh3321 opened 5 months ago

lrh3321 commented 5 months ago

Describe the bug

Output blank png image when use custom font family in windows

To Reproduce Steps to reproduce the behavior:

  1. Execute freeze -x "echo Something" --font.family "Microsoft YaHei" -o freeze.png
  2. Execute explorer freeze.png

Expected behavior

Got an blank image.

Screenshots If applicable, add screenshots to help explain your problem. Snipaste_2024-04-17_20-49-36

Desktop (please complete the following information):

Additional context

Load the default fonts dir may help this

https://github.com/charmbracelet/freeze/blob/80803ebd021ee31dacdf77dca2674d05b0c81b8b/png.go#L50-L57

fontdb.LoadFontsDir(OS_FONTS_DIR)
lrh3321 commented 5 months ago

--font.file option could not help for png format output.Seems embed font file has no effect for github.com/kanrichan/resvg-go .

getify commented 4 months ago

I am having the same problem -- using the linux build of freeze from inside wsl2 on windows 11 -- trying to specify font.family as "Source Code Pro", or setting font.file as the path to the "SourceCodePro-Regular.ttf" file in my windows\fonts directory. Either way, I get a blank .PNG file. If I use "JetBrains Mono" for the font.family, the file renders correctly (but with an undesirable font).

divinedragon commented 3 months ago

I am having the same problem -- using the linux build of freeze from inside wsl2 on windows 11 -- trying to specify font.family as "Source Code Pro", or setting font.file as the path to the "SourceCodePro-Regular.ttf" file in my windows\fonts directory. Either way, I get a blank .PNG file. If I use "JetBrains Mono" for the font.family, the file renders correctly (but with an undesirable font).

Same for me in Ubuntu 22.04

jradtilbrook commented 3 months ago

I'm getting this on mac as well. It looks like the font config is not actually considered on this line: https://github.com/charmbracelet/freeze/blob/578e9d05c3196241fa3c49ce857f9f4c8ae6a77b/png.go#L50

I've had a quick play to see if I can hard code another font file but its not working. Must be more at play here. I'll make do with default font for now as I don't have more time

remino commented 1 month ago

Came here to say I’m having the same issue:

freeze css.css -t dracula --font.family 'Sarasa Term J Nerd Font' --font.size 16 -o css.png

This just outputs a PNG file with a background but no text.