How can I take a screenshot of a website with PHP and GD?

前端 未结 2 2015
情歌与酒
情歌与酒 2020-12-06 14:51

How can I create a screenshot of a website using PHP and the GD library.

相关标签:
2条回答
  • 2020-12-06 15:35

    While you might be able to do something with imagegrabscreen or imagegrabwindow you'd only be able to use it on a Windows box, and even then it would be tricky.

    You'd have to open a browser window to the specified url (you could do that with exec) and grab a screenshot using the aforementioned methods.

    Here's an example from the manual entry for imagegrabwindow:

    <?php
    $browser = new COM("InternetExplorer.Application");
    $handle = $browser->HWND;
    $browser->Visible = true;
    $browser->Navigate("http://www.libgd.org");
    
    /* Still working? */
    while ($browser->Busy) {
        com_message_pump(4000);
    }
    $im = imagegrabwindow($handle, 0);
    $browser->Quit();
    imagepng($im, "iesnap.png");
    imagedestroy($im);
    ?>
    
    0 讨论(0)
  • 2020-12-06 15:47

    Website is rendered on client side, while PHP and GD are server side. You may also check this website out. Hope it helps.

    0 讨论(0)
提交回复
热议问题