当前位置: 首页 > 工具软件 > Img Notes > 使用案例 >

php html jpg,HTML to picture ( php parser for html2jpg / html2pic / html2img )

卫飞鹏
2023-12-01

If you have access to the command line from PHP (via exec() or shell_exec()) you can check out PhantomJS, a headless WebKit browser with a JavaScript API. I use this to do exactly what you're describing:

I generate an HTML file locally

I pass the path of that HTML file and an output path for the image (in my case a PNG) to a bash script that executes a call to PhantomJS (there are great examples when you download the package)

I serve up the generated image

I've tried a LOT of potential solutions and spent many hours on this problem and PhantomJS is by far the easiest I've found. There is a bit of lag waiting for the headless browser to start up, but from what I understand the latest version allows you to keep it running on a port of your choosing. I haven't been able to try this yet. You'll need GhostDriver for this as well. Check out the 1.8 Release Notes for more info.

Good luck!

 类似资料:

相关阅读

相关文章

相关问答