Back to Insights
DevelopersOct 15, 20191 min read

Website Screenshot with PHP in Linux – Solved

Naser Sobhan

Naser Sobhan

AI & Strategy Consultant

Cover for the article: Website Screenshot with PHP in Linux – Solved

I have searched a lot for a proper solution to have websites screenshot with (with and height) and it was not hard until I used different other services on web which was free (limited) and sometimes using google services to solve this issue but I really don’t like to use free services and you know when it’s free there is a limit and it’s not okay and I can’t offered the pricing they have and it was not in my server and this is a problem here.

so I search more until I found a python file opensource project which helped me a lot and it’s actually way easier then using API from free services

https://github.com/maaaaz/webscreenshot

it can be easly instal into your ubuntu machin and will be runable with below command

xvfb-run webscreenshot -w 20 -o $pathtosave -v $url

$pathtosave: is the location that screenshot will be saved

$url: is the link of the webpage

it’s done. no it’s not what about php?

now just use exec function of php to do that job

$pathtosave = '/var/www/screenshots/';
$url = 'https://google.com';
exec("xvfb-run webscreenshot -w 20 -o $pathtosave -v $url");

then you can have your screenshot from google.com in /var/www/screenshots/

Naser Sobhan

Written by

Naser Sobhan

A technology veteran with 18+ years building scalable systems for global enterprises. Now based in Rochester, MN, helping local businesses adopt AI safely and profitably.

How this is written: I'm a builder first, not a professional writer — my strength is the technical work, not turning it into prose. The ideas, opinions, and experience here are entirely mine, shaped by years actually doing this. I use AI to help organize my notes, tighten the language, and turn what's in my head into something worth reading.

Keep reading

All insights →