Miscellaneous
  Home arrow Miscellaneous arrow Page 2 - Flickr Puzzle Mashup
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS

Flickr Puzzle Mashup
By: bluephoenix
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2006-11-13

    Table of Contents:
  • Flickr Puzzle Mashup
  • Getting the Image
  • Slicing the Image
  • Sending the Pieces
  • Client-Side JavaScript
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Flickr Puzzle Mashup - Getting the Image


    (Page 2 of 6 )

    Like many large websites now a day, Flickr offers developers an API they can use to interact with the site's functionality such as uploading new images, deleting old images and getting photo information. Flickr also offers information feeds which we'll be using to find the most recently uploaded image. To see what's available, check out Flickr's API documentation.

    The url api.flickr.com/services/feeds/photos_public.gne provides an Atom1.0 feed of the last 20 uploaded images. The feed is just XML, so we can easily extract the parts we want using PHP's SimpleXML extension. The following is a snippet of the feed:

    <feed>
    <title>Everyone's Photos</title>
    <link rel="self" href="http://api.flickr.com/services/
    feeds/photos_public.gne"/>
    <link rel="alternate" type="text/html" href="http://
    www.flickr.com/photos/"/>
    <id>tag:flickr.com,2005:/photos/public</id>
    <icon>http://www.flickr.com/images/buddyicon.jpg</icon>
    <subtitle>A feed of Everyone's Photos</subtitle>
    <updated>2006-11-03T07:09:03Z</updated>
    <generator uri="http://www.flickr.com/">Flickr</generator>
    <entry>
    <title>Photo 11.jpg</title>
    <link rel="alternate" type="text/html" href="http://
    www.flickr.com/photos/oalvarado7/287495655/"/>
    <id>tag:flickr.com,2005:/photo/287495655</id>
    <published>2006-11-03T07:09:03Z</published>
    <updated>2006-11-03T07:09:03Z</updated>
    <dc:date.Taken>2006-11-02T23:09:03-08:00</dc:date.Taken>
    <content type="html">
    <p><a href="http://www.flickr.com/people/oalvarado7/">oalvarado7
    </a> posted a photo:</p>
    <p><a href="http://www.flickr.com/photos/oalvarado7/287495655/"
    title="Photo 11.jpg"><img src="http://static.flickr.com/100/
    287495655_56c51833bf_m.jpg" width="240" height="180" 
    alt="Photo 11.jpg" style="border: 1px solid #ddd;" /></a></p>
    </content>
    ...

    We're interested in the img tag's src attribute in the first content node.

    <?php
    $feed 
    simplexml_load_file(
      
    "http://www.flickr.com/services/feeds/photos_public.gne");
    $feed simplexml_load_string("&lt;content&gt;" $feed-&gt;entry[0]-&gt;
        
    content[0] . "&lt;/content&gt;");
    $url $feed-&gt;p[1]-&gt;a[0]-&gt;img[0]["src"];
    ?>

    If you've checked the API documentation then you'll know the feed can be obtained in several different formats. While one of the formats is PHP, I feel more comfortable using SimpleXML as opposed to the eval function to get the information.

    Flickr identifies a medium sized image with _m in the image's filename and _o for the image's original size. We can use this knowledge to give users a choice to have their puzzle constructed out of large or small image.

    <?php
    if (isset($_GET["orig"]) &amp;&ampstrtolower($_GET["orig"]) 
      == 
    "true")
      
    $url str_replace("_m""_o"$url);
    ?>

    Now that we have the address of the most recently uploaded image in the desired size, we can retrive a copy of it using file_get_contents and imagecreatefromstring.

    <?php
    $image 
    imagecreatefromstring(file_get_contents($url));
    ?>

    The file_get_contents function retrieves the entire contents of a file and returns it as a string. In this case the file is the image file on the Flickr server. PHP's GD library extension will be used to manipulate the image so we'll need to convert the string into an image in memory using imagecreatefromstring.

    More Miscellaneous Articles
    More By bluephoenix


       · Thanks much for the kickstart on a path I've been meaning to go down for a...
       · Oops! Good catch about the button id... I had 5 other sets of eyes proof the...
     

    MISCELLANEOUS ARTICLES

    - Stopping CSRF Attacks in Your PHP Applicatio...
    - Quick and Dirty AJAX Tutorial
    - Flickr Puzzle Mashup
    - The PAVISE of Security
    - Creating a CAPTCHA with PHP
    - Sending SMS Thru HTTP
    - The Postal Fix - Part 2
    - Adding Mail with Exim
    - The Postal Fix - Part 1
    - Create Your Own Custom API
    - Adding Drop Shadows with PHP
    - Writing a Basic Authentication System in PHP
    - Overlapping Images with GD
    - Using Sockets in PHP
    - Dynamic CSS with PHP






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway