Andrew Hall


Using the Dribbble API for a digital photo frame

After producing the script to scrape FFFFound, I was thinking of some other services to use for a variety of images.
As well as FFFFound, I like to check on what’s happening at Dribbble too.
Dribbble is a site for people to show of their work, that may still be in development, for other designers to comment on.

I used the dribbble api to get the data from dribbble’s servers in JSON format.

Below is my commented script, so steal if it you like and it’s on github too:

//loop through pages
for ($i=1;$i<=30;$i++){
	//Query API and convert to PHP object
	$results = json_decode(file_get_contents("http://api.dribbble.com/shots/popular?page=".$i));
	//Loop through JSON
	foreach ($results->shots as $img){
		//Clean up URL from API
		$img = strstr($img->image_url, '?', true);
		//resizing code to fit the frame from 400x300
		$thumb = imagecreatetruecolor(640, 480);
		if (strcasecmp(substr($img,strrpos($img,".")),".jpg")==0){
			$source = imagecreatefromjpeg($img);
		if (strcasecmp(substr($img,strrpos($img,".")),".gif")==0){
			//ignore if animated gif
			if (is_ani($img)){
			$source = imagecreatefromgif($img);
		if (strcasecmp(substr($img,strrpos($img,".")),".png")==0){
			$source = imagecreatefrompng($img);
		imagecopyresized($thumb, $source, 0, 0, 0, 0, 640, 480, 400, 300);
		// Output
function is_ani($filename) {
    if(!($fh = @fopen($filename, 'rb')))
        return false;
    $count = 0;
    //an animated gif contains multiple "frames", with each frame having a 
    //header made up of:
    // * a static 4-byte sequence (\x00\x21\xF9\x04)
    // * 4 variable bytes
    // * a static 2-byte sequence (\x00\x2C) (some variants may use \x00\x21 ?)
    // We read through the file til we reach the end of the file, or we've found 
    // at least 2 frame headers
    while(!feof($fh) && $count < 2) {
        $chunk = fread($fh, 1024 * 100); //read 100kb at a time
        $count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk, $matches);
    return $count > 1;

Disclaimer: This is meant for personal use only. I don’t encourage using the script to scrape pictures for any purpose other than to view the images.

1 Comment

  1. Evan Boever |

    Pretty! This has been a really wonderful post. Thanks for providing this info.


Leave a comment or tweet me