PHP 8.3.4 Released!

imagegrabwindow

(PHP 5 >= 5.2.2, PHP 7, PHP 8)

imagegrabwindowウィンドウをキャプチャする

説明

imagegrabwindow(int $handle, bool $client_area = false): GdImage|false

ウィンドウあるいはそのクライアント領域のキャプチャを、 ウィンドウハンドル (COM インスタンスの HWND プロパティ) を指定して取得します。

注意:

この関数は Windows 上でのみ使用できます。

パラメータ

handle

HWND ウィンドウ ID。

client_area

アプリケーションのクライアント領域を含めるかどうか。

戻り値

成功した場合に画像オブジェクト、失敗した場合に false を返します。

エラー / 例外

handle が無効なウィンドウハンドルである場合に E_NOTICE、 Windows API のバージョンが古すぎる場合に E_WARNING が発生します。

変更履歴

バージョン 説明
8.0.0 成功時には、 この関数は GDImage クラスのインスタンスを返すようになりました。 これより前のバージョンでは、 resource を返していました。
8.0.0 client_area は、 bool を期待するようになりました。 これより前のバージョンでは、数値型を期待していました。

例1 imagegrabwindow() の例

ウィンドウ (ここでは IE) のキャプチャを行います。

<?php
$browser
= new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$im = imagegrabwindow($handle);
$browser->Quit();
imagepng($im, "iesnap.png");
imagedestroy($im);
?>

ウィンドウ (ここでは IE) の中身のキャプチャを行います。

<?php
$browser
= new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Navigate("http://www.libgd.org");

/* まだ動作するか? */
while ($browser->Busy) {
com_message_pump(4000);
}
$im = imagegrabwindow($handle, 0);
$browser->Quit();
imagepng($im, "iesnap.png");
imagedestroy($im);
?>

参考

add a note

User Contributed Notes 1 note

up
5
nico ->atdot
16 years ago
If you just want to take a screenshot of a website WITHOUT the ugly IE window around it, the easiest way is setting the "Fullscreen" property to TRUE.

$browser->Fullscreen = true;

This is basically the same as pressing F11 once the browser is open, so you just get the actual website.
To Top