0

I am trying to convert a webpage to image on load.

1) fetching data from MySQL database

2) Populating it on a webpage with bootstrap

3) want to show the entire page as one image on the screen.

I tried

header('Content-Type: image/jpg');

but it says some error in the image. When I remove the header it shows no error.

I am sure something is missing here. I googled and SOed it but solutions are not working for me. Please help.

  • 1
    that's not that easy as it sounds, I'm afraid.... – Jeff Mar 07 '18 at 10:16
  • 1
    You can run a headless Chrome, take a screenshot, and stream that image to the browser: https://developers.google.com/web/updates/2017/04/headless-chrome – Robby Cornelissen Mar 07 '18 at 10:20
  • 3
    Possible duplicate of [Website screenshots](https://stackoverflow.com/questions/757675/website-screenshots) – Vishnu Bhadoriya Mar 07 '18 at 10:25
  • @VishnuBhadoriya I have seen that solutions and that does not work for me. It takes a snap of screen and saves it in image file format. I want to convert the webpage to image temporarily. – walimbeakshay Mar 07 '18 at 10:38
  • So what's gonna render your web page into an image? Especially with fairly modern CSS? Answer: a browser. – Robby Cornelissen Mar 07 '18 at 10:48
  • @RobbyCornelissen initially I tried to show it as pdf, but it does not take bootstrap into consideration. So now I have to generate temp image of the content and display on the browser. – walimbeakshay Mar 07 '18 at 11:00
  • 1
    HTML is just a language that browsers understand; if you want to render it (meaning things such as convert it to an image) you need a browser or browser-simulator in order to get such image, see the links the other comments posted here. – Ivan Castellanos Mar 07 '18 at 20:04

0 Answers0