topical media & game development

talk show tell print

mashup-flickr-10-10-1.pl / pl



  #!/usr/bin/perl
  
  use Image::Magick;
  use Flickr::API;
  use XML::Parser::Lite::Tree::XPath;
  
  apikey = 'YOUR-API-KEY';
  apisecret = 'YOUR-API-SECRET';
  
  # Replace this with your NSID
  myNSID = '50317659@N00';
  
  flickr = new Flickr::API(
    {
      'key'    => apikey,
      'secret' => apisecret,
    }); 
  
  response = flickr->execute_method('flickr.photos.search', 
    {
      'user_id' => myNSID,
      'per_page' => 1,
      'page' => 1,
    });
  
  my xpath = new XML::Parser::Lite::Tree::XPath(response->{'tree'});
  
  @photos = xpath->select_nodes('/photos/photo');
  
  image = Image::Magick->new;
  
  if (#photos >= 0)
  {
    photo = photos[0];
    url =  'http://static.flickr.com/' . photo->{'attributes'}->{'server'} . '/' 
       . photo->{'attributes'}->{'id'} . '_' . photo->{'attributes'}->{'secret'} 
       . '_s.jpg';
    image->Read(url);
  }
  
  compositeImage = Image::Magick->new;
  compositeImage->Set(size=>'85x85');
  compositeImage->Read('xc:black');
  compositeImage->Composite(image => image->[0], compose => 'Copy', x => 5, y =>5);
  
  compositeImage->Write(filename => 'image.jpg', quality => 85);
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.