Fork me on GitHub

http2pic


Loading..


Give it a try!

How the API works

http://http2pic.haschek.at/api.php?[OPTIONS]&url=[WEBSITE_URL]



Options

Option Values Description Example
url http://.. The URL of the webpage you'd like to take a screenshot of. Make sure to encode the URL! url=http://xkcd.com
width WIDTH Resizes the screenshot to a specified maximum width. Default value is the original size width=400
viewport WIDTHxHEIGHT Sets the size of the virtual screen rendering the page. Default: smart width, full height viewport=1980x1080
js yes|no Allows you to enable/disable JavaScript in the rendered Website. Default value: yes js=yes
type jpg|png Sets the output file format of the rendered screenshot. Default value: jpg type=png
onfail [url of .jpg] If the page can't be reached, this image will be displayed instead http://http2pic.haschek.at/img/pagefailed.jpg
ondomainfail [url of .jpg] If the web server can't be reached, this image will be displayed instead http://http2pic.haschek.at/img/domainfailed.jpg
cache [any alphanumeric string] If provided, caches the rendered image (based on the URL) so it loads faster on next request. The same cache id with the same url will return the cached image. Change cache id to re-render f01d0

Examples

Simple link via img tag


<?php
    $url = 'http://www.xkcd.com';
    $query = 'type=jpg&viewport=1200x330&url='.rawurlencode($url);
    $img="http://http2pic.haschek.at/api.php?$query";

    echo "<img src='$img' />";
?>
                        

Proxy script to download the image via curl


<?php
    $targeturl = 'http://www.xkcd.com';
    $url = 'http://http2pic.haschek.at/api.php?url='.rawurlencode($targeturl);
	    
    $ch = curl_init($url);
    $fp = fopen('xkcd.jpg', 'wb');
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_exec($ch);
    curl_close($ch);
    fclose($fp);
?>