ウェブサイトの完璧な画像スクリーンショットを作成するか、次の機能を使用してHTMLを直接画像に変換します GrabzItのPHP API。 ただし、開始する前に、 URLToImage, HTMLToImage or FileToImage メソッド Save or SaveTo メソッドを呼び出して画像を作成する必要があります。
Webページのスクリーンショットを撮るために必要なパラメーターは1つだけです HTMLを変換 int画像を 次の例に示すように、
$grabzIt->URLToImage("https://www.tesla.com"); //Then call the Save or SaveTo method
$grabzIt->HTMLToImage("<html><body><h1>Hello World!</h1></body></html>"); //Then call the Save or SaveTo method
$grabzIt->FileToImage("example.html"); //Then call the Save or SaveTo method
GrabzItのPHP APIは、JPG、PNG、WEBP、BMP(8ビット、16ビット、24ビットまたは32ビット)およびTIFFを含む多くの形式で画像を作成できます。 画像のデフォルト形式はJPGです。 ただし、これらの状況の一部のアプリケーションではJPG画像の品質が十分ではない場合があります。品質とファイルサイズのバランスが取れているため、画像のスクリーンショットにはPNG形式が推奨されます。 次の例は、PNG形式を使用して作成される画像を示しています。
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setFormat("png"); $grabzIt->URLToImage("https://www.tesla.com", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.png");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setFormat("png"); $grabzIt->HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.png");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setFormat("png"); $grabzIt->FileToImage("example.html", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.png");
ブラウザーサイズは、ほとんどすべてのタスクでデフォルトのブラウザーサイズで十分なので、ほとんどの場合、スクリーンショットをキャプチャするときに使用されるブラウザーウィンドウのサイズを指します。 ブラウザのサイズを設定するには、単に値を setBrowserWidth
や setBrowserHeight
の方法 GrabzItImageOptions とに提供されます。
画像のサイズを変更するのは簡単です。画像を歪めずに変更するのは少し難しいです。 プロセス全体を簡単にするために、これを使用することをお勧めします シンプルな画像寸法計算機.
画像の幅と高さをブラウザーの幅と高さ(デフォルトでは1366 x 728ピクセル)よりも大きくする場合、ブラウザーの幅と高さも一致するように増やす必要があります。
にカスタム識別子を渡すことができます 画像 次に示すメソッドを使用すると、この値はGrabzIt PHPハンドラーに返されます。 たとえば、このカスタム識別子はデータベース識別子であり、スクリーンショットまたは画像を特定のデータベースレコードに関連付けることができます。
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setCustomId(123456); $grabzIt->URLToImage("https://www.tesla.com", $options); //Then call the Save method $grabzIt->Save("http://www.example.com/handler.php");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setCustomId(123456); $grabzIt->HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", $options); //Then call the Save method $grabzIt->Save("http://www.example.com/handler.php");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setCustomId(123456); $grabzIt->FileToImage("example.html", $options); //Then call the Save method $grabzIt->Save("http://www.example.com/handler.php");
GrabzItを使用すると、Webページ全体のフルスクリーンのスクリーンショットを撮ることができます。これを行うには、-1を渡す必要があります setBrowserHeight
方法。 画像がブラウザのサイズと一致するようにするには、-1を setHeight
や setWidth
方法。
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setBrowserHeight(-1); $options->setWidth(-1); $options->setHeight(-1); $grabzIt->URLToImage("https://www.tesla.com", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.jpg");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setBrowserHeight(-1); $options->setWidth(-1); $options->setHeight(-1); $grabzIt->HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.jpg");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setBrowserHeight(-1); $options->setWidth(-1); $options->setHeight(-1); $grabzIt->FileToImage("example.html", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.jpg");
トリミングされていないスクリーンショットを返すこともできますが、これにより大きな画像が作成される可能性があることに注意してください。 これを行うには、-1を渡します setHeight
および setWidth
メソッド。 -1が渡されたディメンションは切り取られません。
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setWidth(-1); $options->setHeight(-1); $grabzIt->URLToImage("https://www.tesla.com", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.jpg");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setWidth(-1); $options->setHeight(-1); $grabzIt->HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.jpg");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); $options = new \GrabzIt\GrabzItImageOptions(); $options->setWidth(-1); $options->setHeight(-1); $grabzIt->FileToImage("example.html", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.jpg");
これらの特別な値を使用すると、必要に応じてWebページ全体のフルスケールバージョンのスクリーンショットを作成できます。
GrabzItでは、次のようなHTML要素のスクリーンショットを撮ることができます。 div
or span
タグを付け、そのすべてのコンテンツをキャプチャします。 これを行うには、スクリーンショットを撮るHTML要素を CSSセレクター.
... <div id="features"> <img src="http://www.example.com/peace.jpg"/><h3>World Peace Announced</h3> </div> ...
以下の例では、idが「features」のdivを選択し、250 x 250px JPEGイメージとして出力します。
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); // The 250 parameters indicates that image should be sized to 250 x 250 px $options = new \GrabzIt\GrabzItImageOptions(); $options->setWidth(250); $options->setHeight(250); $options->setFormat("jpg"); $options->setTargetElement("#features"); $grabzIt->URLToImage("http://www.bbc.co.uk/news", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.jpg");
次の例では、「機能」divの別のスクリーンショットを撮りますが、今回はdivの正確なサイズであるJPEG画像を出力します。
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret"); // The -1 indicates that image should not be cropped $options = new \GrabzIt\GrabzItImageOptions(); $options->setWidth(-1); $options->setHeight(-1); $options->setBrowserHeight(-1); $options->setFormat("jpg"); $options->setTargetElement("#features"); $grabzIt->URLToImage("http://www.bbc.co.uk/news", $options); //Then call the Save or SaveTo method $grabzIt->SaveTo("result.jpg");