将一段文字转成图片,比如常用的 这里用 PHP 来处理。
text2pic
composer require dsgygb/text2pictouch test.php generate("hello world");print_r($result);#中文字体路径 /c/windows/fonts/sihei.ttf$transform=new Text2pic\Transform($by,$uploadsPath,$uploadsUrl,$fontPath);
wkhtmltopdf
下载后有 2 个工具 wkhtmltoimage 和 wkhtmltopdf 分别是将网页转图片和pdf 的,
#生成图片 https://gist.github.com/vibbow/5702882/user/bin/wkhtmltoimage http://www.baidu.com/ baidu.jpg#php 调用 使用绝对路径$r=shell_exec("/user/bin/wkhtmltoimage http://www.baidu.com/ baidu.jpg");$r=shell_exec("/user/bin/wkhtmltoimage -q {$filename}.html {$filename}.jpg");
phpwkhtmltopdf
# 一个 PHP 库 https://github.com/mikehaertl/phpwkhtmltopdf composer require mikehaertl/phpwkhtmltopdfrequire './vendor/autoload.php';use mikehaertl\wkhtmlto\Image;// You can pass a filename, a HTML string, an URL or an options array to the constructor$image = new Image('/path/to/page.html');$image->saveAs('/path/to/page.png');//保存// ... or send to client for inline display$image->send();//浏览器显示// ... or send to client as file download$image->send('page.png');//浏览器显示并下载#另外一个库 https://github.com/knplabs/snappyuse Knp\Snappy\Pdf as newpdf; $snappy = new newpdf('wkhtmltopdf');header('Content-Type: application/pdf');header('Content-Disposition: attachment; filename="file.pdf"');// echo $snappy->getOutput('http://www.github.com');$snappy->generateFromHtml('Bill
You owe me money, dude.
', 'bill-123.pdf');
more
小人举牌图片生成 https://github.com/jokin1999/HoldUpSignhttps://stackoverflow.com/questions/5663814/how-do-i-get-wkhtmltopdf-to-execute-via-php http://www.jianshu.com/p/4d65857ffe5ehttp://yuncode.net/code/c_51dd01a4d547f26https://github.com/niklasvh/html2canvas 网页保存为图片及高清截图的优化https://segmentfault.com/a/1190000011425316