It started, as so many things do, with a tweet(bark?) from CogDog linking to The Best of ds106 GIF TV. This got me thinking of how to automate the gathering of gifs. I remembered that I had done some gif scraping a while back: Doug’s Gifs.
I wondered about scrapping tumblr in the same manner with a wee bit of php. This turns out to be quite simple: Gifs, Gifs
$url = "http://jjgifs.tumblr.com/rss";
$rss = file_get_contents($url);
$matches = array();
The page Gifs, Gifs, loops through a few ds106naughts tumblrs rather than just the one. It then displays a random gif, clicking on this will display another.
Now I have a text file with a list of ds106 gifs, it is pretty simple to have a
ds106GifAPI! This following image should be a random DS106 gif:
The code used:
<img src="http://johnjohnston.info/oddsandends/ds106gif" alt="a random ds106 gif " />
This should give a random gif every time.
THe DS106 Gif API
Imagine you are blogging (or making any webpage) and want an exciting gif to go with your post, but you don’t just want any old gif, you want a random DS106 gif. Safe for work but not for your mind. Now you casn, simply use http://johnjohnston.info/oddsandends/ds106gif as an image url and you will get a random gif every time the page loads.
Given that my gif store is a list of gif urls the code is simple:
<?php $cachefile = "Path/To/The/Cache/File.txt"; $gifs = file_get_contents($cachefile); $gifArray=explode("\n",$gifs); $thisgif=$gifArray[rand(0,count($gifArray))]; header('Location: '.$thisgif); ?>