Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple HTML layout engine to convert HTML to an image

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. :)

like image 268
gerdemb Avatar asked Dec 04 '08 19:12

gerdemb


People also ask

How can convert HTML image to laravel?

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);


1 Answers

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.

like image 106
gerdemb Avatar answered Sep 28 '22 03:09

gerdemb