Taking screenshots in PHP with a headless browser

Taking screenshots in PHP with a headless browser

adam

Mr. Webwide
Administrator
Local time
20:54
Joined
Sep 24, 2019
Messages
1,264
Pronouns
he/him

Hey everyone! Does anybody have experience using PHP to interact with a headless browser? I am hoping to improve the OpenGraph images both here and for another project. PHP GD is proving a little inflexible and unreliable.

I want to generate the images from HTML and then screenshot them, save them and serve them. I already have a fine system in place in the current one that knows it an image has already been generated and serves that instead.

I guess that PHP is far from optimal for this but it's what I know and have a server set-up to run so balancing that I think it is best. I have root access on server to install whatever.

I'm currently looking at chrome-php (https://github.com/chrome-php/headless-chromium-php) but wondering if anybody knows of a better way to do this? Are there any alternative headless browsers better suited?

 

Gummibeer

Astroneer
Moderator
Local time
21:54
Joined
Oct 5, 2019
Messages
1,187
Pronouns
he/him

adam

Mr. Webwide
Administrator
Local time
20:54
Joined
Sep 24, 2019
Messages
1,264
Pronouns
he/him

But even better: use free vercel service and adjust the HTML & CSS.
I'm using it for my new website.
That looks good! I’m wanting to pull quite a bit in from API’s though so not sure how much I’ll be able to customise that one.

 

Gummibeer

Astroneer
Moderator
Local time
21:54
Joined
Oct 5, 2019
Messages
1,187
Pronouns
he/him

That looks good! I’m wanting to pull quite a bit in from API’s though so not sure how much I’ll be able to customise that one.
I've used it only as a one-time generator. But it's nodejs so you can use request, axios or whatever too.^^

 

Gummibeer

Astroneer
Moderator
Local time
21:54
Joined
Oct 5, 2019
Messages
1,187
Pronouns
he/him

PS: or do your data logic in PHP and pass the final data to the generator URL.
But using a simple Post ID and doing the API work in nodejs should be easier and faster because Vercel scales a thousand times better.

 
Top