Skip to content

Instantly share code, notes, and snippets.

@mikegrassotti
Forked from url2png/url2png-v6.php
Created May 14, 2012 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikegrassotti/2695710 to your computer and use it in GitHub Desktop.
Save mikegrassotti/2695710 to your computer and use it in GitHub Desktop.
v6 Examples
require 'digest' unless defined?(Digest)
# Just in case this isn't a rails app
class Hash
def to_query
require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
map {|k,v| [k,v].map {|p| CGI::escape(p.to_s) }.join('=') }.join('&')
end
end
def url2png_v6 url, options={}
# Get your apikey from http://url2png.com/plans
url2png_apikey = ENV['URL2PNG_API_KEY']
url2png_secret = ENV['URL2PNG_PRIVATE_KEY']
query_string = {
url: url,
force: options[:force] || false, # [false,always,timestamp] Default: false
fullpage: options[:fullpage] || false, # [true,false] Default: false
thumbnail_max_width: options[:thumbnail_max_width]|| false, # scaled image width in pixels; Default no-scaling.
viewport: options[:viewport] || "1280x1024" # Max 5000x5000; Default 1280x1024
}.to_query
token = Digest::MD5.hexdigest(query_string + url2png_secret)
"http://beta.url2png.com/v6/#{url2png_apikey}/#{token}/png/?#{query_string}"
end
# usage
puts url2png_v6 "http://www.google.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment