doumeng3188 2018-02-02 10:57
浏览 54

PHP imagettftext高度重音错误

I'm creating a font converter (ttf to C array) using PHP and imagettftext. It works well but when I convert letters with accent (e.g. Á) the accent is out of the area. In the example I convert some letters with Arial font with 20 px height. (letter, y top coordinate, y bottom coordinate).

  • A: 0 15
  • Á: -4 15
  • y: 4 20
  • Y: 0 15
  • h: 0 15
  • _: 17 20

Generated by this code:

   $co = imagettftext($im, $h_pt, 0, 0, $h_pt, $white, $font, $letter);
   echo($letter . ": " .$co[7] . "  " . $co[1]. "<br>");

The top coordinate of 'Á' is -4 so it not fits to the 0 .. 20 range. How is it possible? I thought the font should fit into its height.

So my question is how to "force" imagettftext to put accents into the given height?

  • 写回答

1条回答 默认 最新

  • dragon071111 2019-08-09 09:05
    关注

    Meanwhile, I've found this article about how font metrics work.

    It turned out that the 20px height doesn't mean the font will fit a 20px heigh line. There are several (sometimes confusing) metrics to determine the height of the ascent and descent parts. This Wikipedia article gives a quick overview.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度