Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert html code to png image using php [duplicate]

Tags:

php

Is there a php script that allow to convert a html code to a png image. The problem with GD library is that only convert text to image( and not html code )

like image 361
mohamed Avatar asked Apr 05 '26 18:04

mohamed


1 Answers

There is no pure PHP solution to this.

Basically you've got two options:

  1. Client-side rendering
    Use something like html2canvas to render your image using javascript in the browser.
  2. Server-side rendering
    Use a library like wkhtmltopdf which can be invoked by PHP to generate the image.
    Another server-side solution would be using Phantom.js which can also run javascript before capturing the screen.
like image 147
Anticom Avatar answered Apr 11 '26 19:04

Anticom