what is the best practice today to generate webpage screenshots via the use of php and js?

i build stuff

I've stumbled upon, but never used it before.
If you're thinking about rolling out your own solution (because it will be a core part of your business), I'd personally roll out something based on Headless Chrome + API. There are already made solutions like…, Docker containers with Headless Chrome, etc.