6

I'm trying to use imagettftext, but apparently it uses point size in GD2, but all of my sizes are in pixels, is there any other function that I can use, or any way to convert pixels to points ?

hakre
  • 193,403
  • 52
  • 435
  • 836
Sina Fathieh
  • 1,727
  • 1
  • 20
  • 35
  • 1
    It seems like it will depend on what GD internally thinks of as the DPI of the image. For example, if the image is 72 DPI, then points are the same as pixels, because 1 point = 1/72 inch. I've been searching for information on whether GD has a DPI setting and how to access it, but no joy so far. – LinusR Oct 19 '12 at 20:01
  • 7
    Just found this PHP bug report that's really old (2002) but seems to have some useful discussion on this issue: https://bugs.php.net/bug.php?id=15656 According to one of the commenters, GD's internal DPI is 96. This squares with my trial-and-error experience trying to match GD's rendered fonts with a PSD file set at 72 DPI. Usually, multiplying the point size from the PSD by 0.75 will get the right size to pass to GD. And 72/96 = 0.75. – LinusR Oct 19 '12 at 20:19

2 Answers2

10

If you're super-lazy, then this might work as an approximation:

$fontsizeinPT = ($fontsizeinPX*3)/4;
Himanshu
  • 31,810
  • 31
  • 111
  • 133
markashworth
  • 1,141
  • 10
  • 17
1

See http://reeddesign.co.uk/test/points-pixels.html

Tyler Eaves
  • 12,879
  • 1
  • 32
  • 39