• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Gregwar/Tex2png: PHP Library to generate PNGs from LaTeX math formula

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

Gregwar/Tex2png

开源软件地址(OpenSource Url):

https://github.com/Gregwar/Tex2png

开源编程语言(OpenSource Language):

PHP 100.0%

开源软件介绍(OpenSource Introduction):

Tex2png

This class provides a way to create easily LaTeX formulas.

With it, you can convert raw formulas like:

\sum_{i = 0}^{i = n} \frac{i}{2}

To nice images like:

Sum formula

Requirement

To use this library you'll need :

  • latex : to compile formulas (with math support)
  • dvipng : to convert dvis to png
  • shell_exec : you need to be able to call the php shell_exec() function

You'll also need a temporary folder and, of courses, enough permissions to write to the target directory

Usage

Just include the Tex2png.php file or register this repository directory as the Gregwar\Tex2png\ namespace and do the following :

<?php

// This will create a formula and save it to sum.png
Tex2png::create('\sum_{i = 0}^{i = n} \frac{i}{2}')
    ->saveTo('sum.png')
    ->generate();

You can have a look at the example in example/ directory.

Using the cache

Tex2png library includes a caching system allowing you to generate images only one time. To do so, just don't tell Tex2png what is the target file :

<?php

Tex2png::create('\sum_{i = 0}^{i = n} \frac{i}{2}')
    ->generate();

// The filename will be choosen using an hash of the formula and
// the image density. (file name will look like cache/tex/3/0/2/e/6/8febefe7aaed9eeb8abf09070d10e02e93e.png)

If the file already exists, it will not generate anything, else, it will generate it. This results in a tiny but powerful caching system avoiding to regenerate a formula PNG twice.

Note that you can change the cache directory calling the setCacheDirectory() function

This is based on the Gregwar/Cache library.

Changing the density

The second constructor/create() parameter is the image density :

<?php

Tex2png::create('\sum_{i = 0}^{i = n} \frac{i}{2}', 300)
    ->generate();

Default density is 155, you can choose to generate really big images, this is an example of the formula with a density of 1000 :

Sum formula (density=1000)

License

This class is under MIT license, for more information, please refer to the LICENSE file




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap