Naser Sobhan

Software Development Consultant

  • Home
  • How can I help?
  • Projects
  • About Me
  • Contact me

Website Screenshot with PHP in Linux – Solved

15/10/2019

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/

Posted in: Developers, Development Projects, source code Tagged: exec, Linux, PHP, screenshot

Blog Posts

  • How can AI help developers to become more productive?
  • Who Is a Software Consultant? How to Become One?
  • How to Gather Requirements for a Software Project Effectively?
  • How to Build a Mobile Application That Meets Your Business Needs?
  • Different Software Engineering Roles You Need to Know

Copyright © 2023 Naser Sobhan.

Me WordPress Theme by themehall.com