Code Samples
1. Minimal example with default options
The default options render a 1360x768 viewport as JPG format. This results in a high quality screenshot that's optimized for the web at only 55kb.
1
2
3
4
5
6
$url = 'https://api.url2thumb.com/v1/capture/' . http_build_query([
'key' => 'YOUR_API_KEY',
'url' => 'https://www.apple.com',
], null, '/');
$signed_url = $url . '?signature=' . hash_hmac('sha256', $url, 'YOUR_API_SECRET');
1
2
3
4
URL="https://api.url2thumb.com/v1/capture/key=YOUR_API_KEY/url=https%3A%2F%2Fwww.apple.com"
SIGNED_URL="$URL?signature=$(echo -n $URL | openssl sha256 -hmac YOUR_API_SECRET)"
curl -vss "$SIGNED_URL" > image.png
1
2
3
4
5
6
7
8
9
require 'uri'
require 'openssl'
url = URI::HTTPS.build(:host => "api.url2thumb.com", path: "/v1/capture/" + URI.encode_www_form({
:key => "YOUR_API_KEY",
:url => "https://www.apple.com",
}).gsub('&', '/')).to_s
signed_url = "#{url}?signature=#{OpenSSL::HMAC.hexdigest("SHA256", "YOUR_API_SECRET", url)}"
Result:
https://api.url2thumb.com/v1/capture/key=YOUR_API_KEY/url=https%3A%2F%2Fwww.apple.com?signature=82616b7d181f0fedc7dde87be2e92369685ae8565fb53578b6dfc56d8ca50ca8
apple.com with default options
2. How to take a fullpage screenshot?
You can take a rich screenshot of the entire webpage using the fullpage
option. By default, the fullpage_scroll
option is also enabled to trigger lazy-loaded elements.
1
2
3
4
5
6
7
$url = 'https://api.url2thumb.com/v1/capture/' . http_build_query([
'key' => 'YOUR_API_KEY',
'url' => 'https://www.apple.com',
'fullpage' => '1',
], null, '/');
$signed_url = $url . '?signature=' . hash_hmac('sha256', $url, 'YOUR_API_SECRET');
1
2
3
4
URL="https://api.url2thumb.com/v1/capture/key=YOUR_API_KEY/url=https%3A%2F%2Fwww.apple.com/fullpage=1"
SIGNED_URL="$URL?signature=$(echo -n $URL | openssl sha256 -hmac YOUR_API_SECRET)"
curl -vss "$SIGNED_URL" > image.png
1
2
3
4
5
6
7
8
9
10
require 'uri'
require 'openssl'
url = URI::HTTPS.build(:host => "api.url2thumb.com", path: "/v1/capture/" + URI.encode_www_form({
:key => "YOUR_API_KEY",
:url => "https://www.apple.com",
:fullpage => "1",
}).gsub('&', '/')).to_s
signed_url = "#{url}?signature=#{OpenSSL::HMAC.hexdigest("SHA256", "YOUR_API_SECRET", url)}"
Result:
https://api.url2thumb.com/v1/capture/key=YOUR_API_KEY/url=https%3A%2F%2Fwww.apple.com/fullpage=1?signature=19cb56f019a7ccf10d9616dd95533341d105170a9fa8d42eaaac7f966416055c
apple.com fullpage WITHOUT fullpage_scroll enabled
apple.com fullpage WITH fullpage_scroll enabled
3. Take a screenshot of a specific part of the page
To take a screenshot of a specific part of a website, use the selector
option to target a specific element ID or CSS classname.
1
2
3
4
5
6
7
8
$url = 'https://api.url2thumb.com/v1/capture/' . http_build_query([
'key' => 'YOUR_API_KEY',
'url' => 'https://www.apple.com',
'selector' => '#tv-plus-gallery',
'delay' => '1',
], null, '/');
$signed_url = $url . '?signature=' . hash_hmac('sha256', $url, 'YOUR_API_SECRET');
1
2
3
4
URL="https://api.url2thumb.com/v1/capture/key=YOUR_API_KEY/url=https%3A%2F%2Fwww.apple.com/selector=%23tv-plus-gallery/delay=1"
SIGNED_URL="$URL?signature=$(echo -n $URL | openssl sha256 -hmac YOUR_API_SECRET)"
curl -vss "$SIGNED_URL" > image.png
1
2
3
4
5
6
7
8
9
10
11
require 'uri'
require 'openssl'
url = URI::HTTPS.build(:host => "api.url2thumb.com", path: "/v1/capture/" + URI.encode_www_form({
:key => "YOUR_API_KEY",
:url => "https://www.apple.com",
:selector => "#tv-plus-gallery",
:delay => "1",
}).gsub('&', '/')).to_s
signed_url = "#{url}?signature=#{OpenSSL::HMAC.hexdigest("SHA256", "YOUR_API_SECRET", url)}"
Result:
https://api.url2thumb.com/v1/capture/key=YOUR_API_KEY/url=https%3A%2F%2Fwww.apple.com/selector=%23tv-plus-gallery/delay=1?signature=5966b5de0b7473d1659dd6ac308976cf78a42160409121e51510002fce816182
apple.com specific element