If I know the font size (12) and the font family (calibri), is there a way to determine the length (in pixels) a given string will take after it will be rendered? I am absolutely certain about the font and size. Are there any lookup tables for this purpose to determine the length in PHP code itself? I am writing a PHP script to dynamically generate an SVG image which contains various boxes filled with data pulled out of a DB. The problem is that I need to manually wrap the text around and increase the size of the box if the string is big.

如果我知道字体大小(12)和字体族(calibri),是否有办法确定给定字符串在呈现后的长度(以像素为单位)?我非常确定字体和大小。有查找表来确定PHP代码本身的长度吗?我正在编写一个PHP脚本,以动态地生成一个SVG图像,其中包含从DB中取出的数据填充的各种方框。问题是,如果字符串很大,我需要手工包装文本,并增加盒子的大小。

Thanks

谢谢

5 个解决方案

#1


16

Use the PHP function imagettfbbox to get the size of the bounding box for the given string.

使用PHP函数imagettfbbox获取给定字符串的边框大小。

On the other hand you can use also javascript to manipulate SVG images in case you would like to handle it on the client side. That way it wouldn't even matter if the client had the specified font or not...

另一方面,如果希望在客户端处理SVG图像,也可以使用javascript来操作SVG图像。这样的话,客户端是否有指定的字体都没有关系……

更多相关文章

  1. AngularJS使用双向数据绑定将img元素标签中的图像显示为源?
  2. 具有不间断空格的呈现字符串
  3. js字符串与html代码互相转换时怪想法:自己解析js字符串成普通字
  4. iOS:从NSString中删除(一个html字符串)
  5. 图像未加载到HTML页面的jQuery load()中
  6. JQuery查找并更改字符串的样式
  7. 为什么v-align中的将文本放在图像下面
  8. 如何截取html的子字符串作为内容摘要
  9. 如果字符串包含html代码,如何用python检测?

随机推荐

  1. 润乾报表实用教程
  2. Java第三次作业——面向对象基础(封装)
  3. JavaScript原型彻底理解2---继承中的原型
  4. 【Java】通过原始Servlet写最基本的Web应
  5. java文件上传输入输出流的问题
  6. JAVAONE 2016大会的所见所感
  7. eclipse 中安装android ADT时问题解决‘o
  8. java调用Kettle总结
  9. idea使用spring boot 热更新、热加载
  10. 20155320 《Java程序设计》实验五网络编