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

前端 未结 2 2113
情歌与酒
情歌与酒 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:

    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);
    ?>
    

提交回复
热议问题