Your personal unique identifier.
Assigned to you during the signup process.
Starts with the letter "P"
A security token to prevent unauthorized use of your account.
You will need to generate this for each unique request.
It is the md5 hash of the entire query string and your SECRETKEY
Your target site's URL, urlencoded
# See also
# https://rubygems.org/gems/url2png
require 'cgi' unless defined?(CGI)
require 'digest' unless defined?(Digest)
class Url2png
attr_reader :apikey, :secret, :query_string, :token
def initialize options
@apikey = 'PXXX'
@secret = 'SXXX'
@query_string = options.sort.map { |k,v| "#{CGI::escape(k.to_s)}=#{CGI::escape(v.to_s)}" }.join("&")
@token = Digest::MD5.hexdigest(query_string + secret)
end
def url
"http://api.url2png.com/v6/#{apikey}/#{token}/png/?#{query_string}"
end
end
options = {
url: "http://www.google.com",
thumbnail_max_width: 500,
viewport: "1480x1037",
fullpage: true,
unique: Time.now.to_i / 60 / 60 # forces a unique request at most once an hour
}
puts Url2png.new(options).url
#!/bin/bash
APIKEY="PXXXXXXXXXXXXX"
SECRET="S_XXXXXXXXXXXX"
TOKEN=$(echo -n "?url=google.com&fullpage=true$SECRET" | md5sum | cut -d " " -f 1)
curl -vvs "https://api.url2png.com/$APIKEY/$TOKEN/?url=google.com&fullpage=true" > test.png
import hashlib
import urllib.parse
def url2png(url, apikey, secret, fullpage=None, max_width=None,
unique=None, viewport_width=1280, viewport_height=1024):
data = {
'url': url,
'fullpage': 'true' if fullpage else 'false',
'thumbnail_max_width': max_width,
'unique': unique,
'viewport': '{}x{}'.format(viewport_width, viewport_height),
}
filtered_data = dict((opt, data[opt]) for opt in data if data[opt])
query_string = urllib.parse.urlencode(filtered_data)
token = hashlib.md5('{}{}'.format(query_string, secret).encode('utf-8')).hexdigest()
return "http://api.url2png.com/v6/{}/{}/png/?{}".format(apikey, token, query_string)
apikey="PXXXX"
secret="SXXXX"
print(url2png("http://google.com/", apikey, secret))
// See also
// https://www.npmjs.com/package/url2png
var url2png = require('url2png')('API_KEY', 'PRIVATE_KEY');
var options = {
viewport : '900x600',
thumbnail_max_width : 400,
protocol: 'http'
}
//Get the URL
var url = url2png.buildURL('google.com' options);
//...or download the image to a file
var fs = require('fs');
url2png.readURL('google.com' options).pipe(fs.createWriteStream('google.png'));
//...or send the image in the http response
var http = require('http');
http.createServer(function (req, res) {
if (req.url === '/google.png') {
url2png.readURL('google.com' options).pipe(res)
}
});
<?php
# See also
# codeigniter - https://github.com/gkimpson/url2png-codeigniter
# wordpress - https://wordpress.org/plugins/url2png-screenshots/
# drupal - https://www.drupal.org/project/url2png
function url2png_v6($url, $args) {
$URL2PNG_APIKEY = "PXXXX";
$URL2PNG_SECRET = "SXXXX";
# urlencode request target
$options['url'] = urlencode($url);
$options += $args;
# create the query string based on the options
foreach($options as $key => $value) { $_parts[] = "$key=$value"; }
# create a token from the ENTIRE query string
$query_string = implode("&", $_parts);
$TOKEN = md5($query_string . $URL2PNG_SECRET);
return "https://api.url2png.com/v6/$URL2PNG_APIKEY/$TOKEN/png/?$query_string";
}
# usage
$options['unique'] = round(time()/60/60,0); # Limit capture to once per hour
$options['fullpage'] = 'false'; # [true,false] Default: false
$options['thumbnail_max_width'] = 'false'; # scaled image width in pixels; Default no-scaling.
$options['viewport'] = "1280x1024"; # Max 5000x5000; Default 1280x1024
$src = url2png_v6("google.com", $options);
' VB.NET Example
' Supplied by Thomas Kristensen
Public Shared Function url2png(ByVal UrlToSite As String) As String
Dim url2pngAPIKey As String = "API_KEY"
Dim url2pngPrivateKey As String = "PRIVATE_KEY"
Dim url As String = HttpUtility.UrlEncode(UrlToSite)
Dim SecurityHash As String = Md5HashPHPCompliant(_url2pngPrivateKey & "+" & url).ToLower
Return "http://api.url2png.com/v3/" & _url2pngAPIKey & "/" & SecurityHash & "/" & "100x100/" & url
End Function
Public Shared Function Md5HashPHPCompliant(ByVal pass As String) As String
Dim md5 As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim dataMd5 As Byte() = md5.ComputeHash(Encoding.UTF8.GetBytes(pass))
Dim sb As New StringBuilder()
For i As Integer = 0 To dataMd5.Length - 1
sb.AppendFormat("{0:x2}", dataMd5(i))
Next
Return sb.ToString()
End Function
use URI::Escape qw(uri_escape);
use Digest::MD5 qw(md5_hex);
sub url2png {
my $url = shift;
my $url2png_apikey = shift;
my $url2png_secret = shift;
my $options = shift;
my $url2png_apiurl = 'https://api.url2png.com/v6';
$query_string = 'url=' . uri_escape($url);
if(defined($options)) {
foreach my $k (keys %$options) {
$query_string .= "&$k=" . uri_escape($options->{$k});
}
}
my $token = md5_hex($query_string . $url2png_secret);
return("$url2png_apiurl/$url2png_apikey/$token/png/?$query_string");
}
print url2png('http://google.com', 'PXXX', 'SXXX', {'thumbnail_max_width' => '300', 'fullpage' => 'true'}) . "\n";
public static string url2png(string UrlToSite)
{
string url2pngAPIKey = "PXXX";
string url2pngPrivateKey = "SXXX";
string url = HttpUtility.UrlEncode(UrlToSite);
string getstring = "fullpage=true&url=" + url;
string SecurityHash_url2png = Md5HashPHPCompliant(url2pngPrivateKey + "+" + getstring).ToLower();
var url2pngLink = "http://api.url2png.com/v6/" + url2pngAPIKey + "/" + SecurityHash_url2png + "/" + "png/?" + getstring;
return url2pngLink;
}
public static string Md5HashPHPCompliant(string pass)
{
System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] dataMd5 = md5.ComputeHash(Encoding.UTF8.GetBytes(pass));
StringBuilder sb = new StringBuilder();
for (int i = 0; i <= dataMd5.Length - 1; i++)
{
sb.AppendFormat("{0:x2}", dataMd5[i]);
}
return sb.ToString();
}
Constrain screenshot based on width.
&thumbnail_max_width=500
1:1
Set viewport dimensions, adjust to your hearts content.
&viewport=500x500
1480x1037
Will attempt to capture entire document canvas.
&fullpage=true
false, viewport only
Forces a fresh screenshot by varying this value. We suggest using a timestamp.
&unique=2015-01-29_07:03:00
false
Inject your own CSS into any page.
&custom_css_url=http://url2png.com/tests/css/test.css
false
Delay screenshot until <div id='url2png-cheese'></div>
is available.
&say_cheese=true
false
Override the default HTTP Accept-Language header
&accept_languages=de
en-US,en;q=0.8
Delay screenshot for a fixed number of seconds past document ready and assets loading. Generally this is only needed for flash animations etc.
&delay=2
Set the TTL or "time to live" value for a screenshot in seconds. See unique to generate fresh captures.
&ttl=5184000
2592000 (30 days)