PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 10, 2022

[FIXED] How can I take a screenshot of a page with GD?

 October 10, 2022     gd, php, screenshot     No comments   

Issue

I am trying to take a screenshot of a page using GD library but as a result Screen capture only returns a black image.

<?php
header('Content-type: text/html; charset=windows-1251');
?>

<?php
header("Location:http://10.32.172.30:9080/RTOnline/b/p/115");
$img = imagegrabscreen();
imagepng($img, 'screenshot.png');
?>


Solution

Well you can use a command line tool to take a screenshot of a webpage. You can run the tool within Php using shell_exec function. For example the wkhtmltopdf command line tool allows converting from html to pdf and other formats.

If the web page contains complex JavaScript or Ajax, then you can use a headless browser to take the screenshot. For example see: Chrome Headless. Also see the Html2Canvas script. It allows taking screenshots using JavaScript.

Also see this question: Website screenshots



Answered By - Nadir Latif
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing