I’m lucky that I religiously upload all my “ok” photographs to Flickr rather than just my best ones. While I have been criticised more than once for this practice it just saved me a lot of grief. After deciding the photolabs to go with we needed to choose the photographs we were going to have developed. That is when I discovered I had lost a whole set of pictures.
What I usually do is while away download to the laptop, when I get back I archive off onto DVD and an external hard drive. Since getting the DVR though I have started doing slide shows so we have the video and pics on the same disk for showing friends and family (double the punishment). This means there is only the hard drive backup. I looked for our december trip on there and couldn’t find it.
It’s ok, I thought, all the decent ones are on flickr. Which is true. But how the heck do you download over a hundred pictures from flickr? There doesn’t seem to be an easy way!
Luckily I am a programmer
Using the Flickr API, with the help of the phpFlickr wrapper, I quickly knocked up a downloader script. Because the download could go into gigabytes I am not going to upload it in a working website for you to try but you are free to use it yourself. I recommend running it locally rather than on your web space. Apart from taking an hour to download all my pics I am happy to say it worked.
To use this script you need PHP (with GD) running on your own computer and an API key.
Edit the script to enter your API key, your “secret” and the id of the photoset you wish to download. Right now it is set to download the original sized photographs into a subdirectory of the current working directory called “download”.
Update Feb 2008
The original code was borked by some breaking changes so here is some new code to download.
-
<?php
-
-
// set the script to never time out
-
set_time_limit(#31phpFlickr24#);
-
ini_set(‘error_reporting’, E_ALL);
-
-
require_once(“phpFlickr.php”);
-
-
print “<h1>Download Flickr Photos</h1>”;
-
-
// edit this line to include your api key and secret
-
$f = new phpFlickr(“KEYKEYKEY”,‘SECRETSECRET’);
-
-
if($f) print “API ok”;
-
-
//get the photos from a set - enter the id of the set
-
$photos = $f->photosets_getPhotos(“72157600055030487″,null);
-
-
if($photos) print ” got photos ..”;
-
-
// Loop through the photos and output the html
-
foreach ($photos[#24##33#'photo'#24##30#] as $photo) {
-
-
// get image URLs
-
$photoSizes = $f->photos_getSizes($photo[#24##33#'id'#24##30#]);
-
$originalSizeURL = $photoSizes[#24##38##28#count#24##29##30#(#24##36#$photoSizes#24##30#)#24# - #31#1#24##30#][#24##33#'source'#24##30#];
-
$thumbURL = $f->buildPhotoURL($photo, “square”);
-
-
// display the thumbnail
-
echo “<img alt=”.$photo[#24#title#30#].” src=\”$thumbURL\”>”;
-
-
// download the original version
-
grabPic($originalSizeURL,$photo[#24#title#30#].“_”.$photo[#24#id#30#]);
-
-
-
-
}
-
-
function grabPic($URL,$title)
-
{
-
$filename=makeFilename($title).“.jpg”;
-
$source = $URL;
-
$newimage = imageCreateFromJPEG($source);
-
-
// I have it set to download to a folder called “download”
-
if(imageJPEG($newimage,“download/”.$filename,85))
-
{
-
imageDestroy($newimage);
-
print “`\n $filename Downloaded”;
-
}
-
else
-
{
-
print “oops can’t download “ . “download/”.$filename;
-
}
-
}
-
-
function makeFilename($string)
-
{
-
-
return preg_replace(“/[^A-Za-z0-9]/”, “_”, $string);
-
}
-
-
?>
Technorati Tags: flickr, tools, download, php, programming, phpflickr, backup, tips, photography
powered by performancing firefox
