Skip to content

Instantly share code, notes, and snippets.

@url2png
Last active October 4, 2015 16:18
Show Gist options
  • Save url2png/2667118 to your computer and use it in GitHub Desktop.
Save url2png/2667118 to your computer and use it in GitHub Desktop.
v6 Examples
<?php
function url2png_v6($url, $args) {
# Get your apikey from http://url2png.com/plans
$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 "http://beta.url2png.com/v6/$URL2PNG_APIKEY/$TOKEN/png/?$query_string";
}
# usage
$options['force'] = 'false'; # [false,always,timestamp] Default: false
$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);
import urllib
import hashlib
class Url2png(object):
def __init__(self, options):
self.apikey = 'PXXXX'
self.secret = 'SXXXX'
self.query_string = urllib.urlencode(options)
self.token = hashlib.md5(self.query_string + self.secret).hexdigest()
@property
def url(self):
return "http://api.url2png.com/v6/%s/%s/png/?%s" % (self.apikey, self.token, self.query_string)
options = {
'url': "http://www.google.com",
'viewport': "1024x768",
'thumbnail_max_width': 200,
}
print Url2png(options).url
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 # forces a unique request at most once an hour
}
puts Url2png.new(options).url
@mpdaugherty
Copy link

I added a python version of this function here: https://gist.github.com/3774987

Seems to be working ok for me so far. Thanks for the easy API!

@gabemartinez
Copy link

I want to thank you very much for this. The php version was very helpful!

@roborew
Copy link

roborew commented Jun 26, 2013

I've created a php class here.. https://github.com/Roboco/urltopng

thanks for the service ;-)

@prettymuchbryce
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment