Strumenti per acquisire e convertire il Web

Cattura schermate di siti Web o converti HTML in immagini

API Perl

Crea schermate di immagini perfette di siti Web o converti HTML direttamente in immagini utilizzando le seguenti funzionalità di API Perl di GrabzIt. Tuttavia, prima di iniziare, ricordare che dopo aver chiamato il URLToImage, HTMLToImage or FileToImage metodi il Save or SaveTo Il metodo deve essere chiamato per creare l'immagine.

Opzioni di base

È necessario un solo parametro per acquisire uno screenshot di una pagina Web o converti HTML into immagine come mostrato nell'esempio seguente.

$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

Formati immagine

L'API Perl di GrabzIt può creare immagini in diversi formati, tra cui JPG, PNG, WEBP, BMP (bit 8, bit 16, bit 24 o bit 32) e TIFF. Il formato predefinito per gli screenshot delle immagini è JPG. Tuttavia, la qualità di un'immagine JPG potrebbe non essere abbastanza buona per alcune applicazioni in queste circostanze, il formato PNG è raccomandato per le schermate di immagini in quanto fornisce un buon equilibrio tra qualità e dimensione del file. L'esempio seguente mostra uno screenshot di immagine acquisito utilizzando il formato PNG.

$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItImageOptions->new();
$options->format("png");

$grabzIt->URLToImage("https://www.tesla.com", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.png");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItImageOptions->new();
$options->format("png");

$grabzIt->HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.png");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItImageOptions->new();
$options->format("png");

$grabzIt->FileToImage("example.html", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.png");

Dimensione del browser

La dimensione del browser si riferisce alla dimensione della finestra del browser che verrà utilizzata durante l'acquisizione dello screenshot nella maggior parte dei casi, ciò non deve essere impostato poiché la dimensione predefinita del browser sarà sufficiente per tutte le attività. Per utilizzare la dimensione del browser predefinita basta passare 0 Vai all’email browserWidth ed browserHeight metodi del GrabzItImageOptions classe.

Cambia dimensione immagine

Cambiare le dimensioni di un'immagine è facile, farlo senza distorcere l'immagine è un po 'più difficile. Per semplificare l'intero processo, ti consigliamo di utilizzarlo semplice calcolatore delle dimensioni dell'immagine.

Se si desidera aumentare la larghezza e l'altezza dell'immagine ad una dimensione maggiore della larghezza e dell'altezza del browser, che per impostazione predefinita è 1366 per pixel 728, è necessario aumentare anche la larghezza e l'altezza del browser in modo che corrispondano.

Identificatore personalizzato

È possibile passare un identificatore personalizzato a Immagine metodi come mostrato di seguito, questo valore viene quindi restituito al gestore GrabzIt Perl. Ad esempio, questo identificatore personalizzato potrebbe essere un identificatore del database, consentendo di associare uno screenshot a un particolare record del database.

$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItImageOptions->new();
$options->customId("123456");

$grabzIt->URLToImage("https://www.tesla.com", $options);
# Then call the Save method
$grabzIt->Save("http://www.example.com/handler.pl");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItImageOptions->new();
$options->customId("123456");

$grabzIt->HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", $options);
# Then call the Save method
$grabzIt->Save("http://www.example.com/handler.pl");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItImageOptions->new();
$options->customId("123456");

$grabzIt->FileToImage("example.html", $options);
# Then call the Save method
$grabzIt->Save("http://www.example.com/handler.pl");

Screenshot a figura intera

GrabzIt ti permette di fare uno screenshot completo di un'intera pagina web per fare questo è necessario passare un -1 al browserHeight metodo. Per assicurarsi che l'immagine corrisponda alle dimensioni del browser, passare un -1 al file height ed width metodi.

$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItImageOptions->new();
$options->browserHeight(-1);
$options->width(-1);
$options->height(-1);

$grabzIt->URLToImage("https://www.tesla.com", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.jpg");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItImageOptions->new();
$options->browserHeight(-1);
$options->width(-1);
$options->height(-1);

$grabzIt->HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.jpg");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItImageOptions->new();
$options->browserHeight(-1);
$options->width(-1);
$options->height(-1);

$grabzIt->FileToImage("example.html", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.jpg");

Puoi anche restituire miniature che non sono ritagliate, ma fai attenzione perché puoi creare immagini di grandi dimensioni. Per fare questo passare un -1 al file height e / o width metodi. La dimensione che viene passata a -1 non verrà ritagliata.

$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItImageOptions->new();
$options->width(-1);
$options->height(-1);

$grabzIt->URLToImage("https://www.tesla.com", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.jpg");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItImageOptions->new();
$options->width(-1);
$options->height(-1);

$grabzIt->HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.jpg");
$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = GrabzItImageOptions->new();
$options->width(-1);
$options->height(-1);

$grabzIt->FileToImage("example.html", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.jpg");
Nota che non esiste una larghezza del browser a lunghezza intera!

L'uso di questi valori speciali nei metodi altezza, larghezza e altezza di output del browser significa che è possibile creare uno screenshot delle dimensioni esatte dell'intera pagina Web, se lo si desidera!

Cattura uno screenshot di un elemento della pagina

GrabzIt ti permette di fare uno screenshot di un elemento HTML, come a div or span tag e acquisisci tutto il suo contenuto. Per fare ciò, l'elemento HTML che vuoi catturare deve essere specificato come Selettore CSS.

...
<div id="features">
	<img src="http://www.example.com/boy.jpg"/><h3>Boy Found</h3>
</div>
...

Nello snippet di codice riportato di seguito visualizzeremo il div con l'id "caratteristiche" e lo restituiremo come immagine JPEG 250 x 250px.

$grabzIt = GrabzItClient->new("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 = GrabzItImageOptions->new();
$options->width(250);
$options->height(250);
$options->format("jpg");
$options->targetElement("#features");

$grabzIt->URLToImage("http://www.bbc.co.uk/news", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.jpg");

L'esempio seguente crea un altro screenshot del div "features" ma questa volta genera un'immagine JPEG della dimensione esatta del div nel browser.

$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");

# The -1 indicates that image should not be cropped
$options = GrabzItImageOptions->new();
$options->width(250);
$options->height(250);
$options->browserHeight(-1);
$options->format("jpg");
$options->targetElement("#features");

$grabzIt->URLToImage("http://www.bbc.co.uk/news", $options);
# Then call the Save or SaveTo method
$grabzIt->SaveTo("result.jpg");