I need a tool to automatically convert simple HTML into an image. I will be controlling the HTML input which will consist of simple text formatting tags and possibly image links--I don't need to be able to render arbitrary HTML. Is there a simple way to do this?
I've looked at the HTML layout engines like Gecko and Webkit, but frankly I'm overwhelmed by the number of options they have--I don't need a complete web browser! Is it possible to use these engines in this way? Can someone steer me in the right direction?
Other possibilities like browsershots, rely on screenshots of real browsers, but I'm going to be running this application on a web server with potentially many users so performance is important and I'm afraid this kind of solution won't scale.
Ideas?
EDIT: Sorry forget to mention that my server is running Linux, so Windows solutions won't help. :)
use Spatie\Browsershot\Browsershot; Browsershot::url('https://example.com')->save($pathToImage); Browsershot::url('https://example.com') ->setScreenshotType('jpeg', 100) ->save($pathToImage); Browsershot::url('https://example.com') ->windowSize(640, 480) ->save($pathToImage);
Answering, my own question I found this useful tool which uses WebKit to render a page and then captures the output as an image or even in PDF format!
http://cutycapt.sourceforge.net/
The idea is similar to khtml2png mentioned by Jay, but I liked this implementation better. Also, for future reference, running an X virtual frame-buffer through Xvfb is not nearly as memory intensive as I had feared.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With