Live data from Hacker News

Ask HN: How to Convert HTML to PNG on a Serverside?

news.ycombinator.com

1–10 of 16 posts

Ask HN: How to Convert HTML to PNG on a Serverside?

#1
Hello everyone!

I need an advice. I work on a web app, that needs to send PNG images to users based on their achievements. The easiest way to do that is to construct an HTML that contains all the information, make a screenshot of it and finally upload it to the server. But this solution is extremely not optimal.

So I'm curious how to implement the same logic, but without frontend involvement in terms of image generation. I know that there are many commercial libs and services for that, but maybe there is some open-source more or less good libs for that.

I'm fine to work with Java, Scala, NodeJS or Golang.

Any advice is welcome!

Re: Ask HN: How to Convert HTML to PNG on a Serverside?

#2
There are libraries for converting HTML to PNG. Why would you need the frontend for anything?

Grab the users' achievement from the database(I could only assume user data is stored here). Format it however you want it to look in an HTML file then convert said HTML to a PNG. Its dead simple.

I did the equivalent but with PDF's for customer bills for a past job.

Re: Ask HN: How to Convert HTML to PNG on a Serverside?

#4

There are libraries for converting HTML to PNG. Why would you need the frontend for anything? Grab the users' achievement from the database(I could only assume user data is stored here). Format it however you want it to look in an HTML file then convert said HTML to a PNG. Its dead simple. I did the equivalent but with PDF's for customer bills for a past job.

the main point here — I can not find any good lib with good community on GitHub I know there is html2image-java, but it's not maintained for a while :(

Re: Ask HN: How to Convert HTML to PNG on a Serverside?

#5

Headless chrome/puppeteer...

No-no Headless chrome / firefox doesn't work here, since I need to run Selenium on the server and that's the most obvious overhead because any browser, even in a headless mode consumes RAM. This becomes even more critical if you need to process more than 100 images per minute :|

Re: Ask HN: How to Convert HTML to PNG on a Serverside?

#7

Headless chrome/puppeteer...

No-no Headless chrome / firefox doesn't work here, since I need to run Selenium on the server and that's the most obvious overhead because any browser, even in a headless mode consumes RAM. This becomes even more critical if you need to process more than 100 images per minute :|

From experience 100 images / min with chrome and puppeteer (you don't need Selenium) is more than doable with less than 1gb ram.

Re: Ask HN: How to Convert HTML to PNG on a Serverside?

#9

Headless chrome/puppeteer...

No-no Headless chrome / firefox doesn't work here, since I need to run Selenium on the server and that's the most obvious overhead because any browser, even in a headless mode consumes RAM. This becomes even more critical if you need to process more than 100 images per minute :|

You could roll your own fairly easily with qt webkit and a mere smidgen of c++. But it'd probably be similar yo puppeteer. Maybe you can save some time by not creating a new instance of puppeteer for each image.
Post reply on HN