0

When using the gd2 library, I can load a variable font with

imagettftext($image, 24, 0, 10, 100, $black, __DIR__.'/Some-VariableFont.ttf', 'Hello, World!');

But I can't figure out how to set properties such as weight or width.

Is it possible? If yes how?

SteeveDroz
  • 6,006
  • 6
  • 33
  • 65
  • 1
    In terms of "sizing" it to a specific height and width? The 2nd param "24" is the font size, so you need more control? You could pre-render then resize as approriate. The "weight" would probably just be a different version of the font. – GetSet Dec 10 '20 at 08:26
  • I have static versions of this font, but I want to change the font weight randomly (and therefore programmatically). I don't want to have TTF files for each weight, for obvious reasons. But feel free to transform your comment into an answer: I was asking "Is it possible?" to which "No" is a reasonable answer, especially if you give an alternative. – SteeveDroz Dec 10 '20 at 08:52
  • Its certainly possible. You could for example make "weight" by repeating the text draw over a 1-D or 2-D range. .... Terms of setting a width and height, I meant drawing the text to another image buffer, then resizing that "rectlinear" as you see fit. – GetSet Dec 10 '20 at 08:54
  • Maybe [this answer](https://stackoverflow.com/a/65447234/9193372) should help – Syscall Jan 28 '21 at 19:08
  • No it doesn't, my text is displayed, but I'd like to change its weight… – SteeveDroz Oct 17 '21 at 06:46

1 Answers1

0

FreeType has variable font support but GD provides no API to use it, so the answer is "no".

Olivier
  • 13,283
  • 1
  • 8
  • 24
  • That was probably the easiest points you ever won, wasn't it? I should have asked "How do I do it?" instead of "Can I do it this way". Too bad for me and good thing for you! – SteeveDroz Oct 21 '21 at 14:45