Motyar

@motyar

Freelance Web Developer

Static Web Hosting, made easy

Sep 2, 2012

Get the Image link of a Tumblr post

I was trying trying IFTTT and wanted to save my Tumblr liked image post to Dropbox. Searched Google for it but found nothing I can get direct image link with post url. So I decided to scrape post html to get link.

TIP: When you have to scrape and web page think about its mobile version, they are always light weighted and with simple dom structures.

Tumblr provides a mobile version for their blogs, you can open this my simply putting /mobile at  the end of home page url. So its its xyz.tumblr.com, mobile version ll be at xyz.tumblr.com/mobile.

Here is simple PHP function that returns the image permalink by post url.



$url = explode("/", $_GET['u']);
$data = file_get_contents("http://".$url[2]."/mobile/post/".$url[4]);
preg_match_all('<a href="(.*?)">',$data,$matches,PREG_PATTERN_ORDER);
//check if high res big image available
if(file_get_contents(str_replace("_500","_1280",$matches[1][0]))){
header('Location:'.str_replace("_500","_1280",$matches[1][0]));
}
else{
header('Location:'.$matches[1][0]);
}
exit();

Hope this ll help you.

Labels: , , ,




By :