Professional Documents
Culture Documents
O ver two million regis tered Flic kr us ers and c ounting have
dis c overed the eas e and fun of organizing their photo libraries ,
s howing off their favorite pic tures to the world, and s ec urely
s haring their private pic tures with friends , family, or ad hoc
groups . But Flic kr's own plethora of intuitive menus , options ,
and features jus t s c ratc hes the s urfac e.
Set random des ktop bac kgrounds and build your own
Flic kr s c reens aver
M ake your own Flic kr- s tyle tag c loud to vis ualize the
frequenc y of c ommon tags
Copyright
Preface
Why Flickr Hacks?
How to Use This Book
How to Run the Hacks
How This Book Is Organized
Conventions Used in This Book
Using Code Examples
How to Contact Us
Got a Hack?
Safari Enabled
Chapter 1. Sharing Photos
Hacks 1-9
Hack 1. Store, Sort, and Share Your Photos
Hack 2. Control Who Sees Your Photos
Hack 3. Manage Image Metadata
Hack 4. Resize Photos for Flickr
Hack 5. Add Photos Quickly
Hack 6. Post Pictures from Your Cell Phone
Hack 7. Feed Your Latest Photos to Your Web Site
Hack 8. Make a Photo Gallery in 30 Seconds or Less
Hack 9. Post Photos to Your Blog
Chapter 2. Tagging Photos
Hacks 10-14
Hack 10. Describe Your Photos
Hack 11. Play w ith Tags
Hack 12. Geotag Your Photos
Hack 13. Exploit Compound Tags
Hack 14. Make a Flickr-Style Tag Cloud
Chapter 3. View ing Photos
Hacks 15-23
Hack 15. Add Flickr Search to Firefox
Hack 16. Find Pictures You Can Reuse Legally
Hack 17. Subscribe to Flickr
Hack 18. Rate Photos
Hack 19. Travel w ith Flickr
Hack 20. Build a Custom Flickr Feed
Hack 21. Set Random Desktop Backgrounds
Hack 22. Build a Flickr Screensaver
Hack 23. View Flickr Photos on TiVo
Chapter 4. Community
Hacks 24-29
Hack 24. Add and Track Contacts
Hack 25. Track Your Friends' Favorites
Hack 26. Find Your Friends' Favorite Tags
Hack 27. Map Your Contacts
Hack 28. Find Flickrites in Your Mac Address Book
Hack 29. Surf Your Contacts
Chapter 5. Maintenance
Hacks 30-36
Hack 30. Back Up Your Photos
Hack 31. Back Up Photo Comments
Hack 32. Make a Contact Sheet
Hack 33. Dow nload a List of Photos
Hack 34. Cache Photos Locally
Hack 35. Edit Photos as a Batch
Hack 36. Clean the (Group) Pool
Chapter 6. API Basics
Hacks 37-42
The API Page
API Methods
API Keys and Secrets
Identifying Users
Identifying Groups
Identifying Photos
Deconstructing Flickr URLs
Talking to the API
Hack 37. Talk to the API w ith Your Web Brow ser
Hack 38. Talk to the API w ith Perl
Hack 39. Talk to the API w ith PHP
Hack 40. Authenticate Yourself
Hack 41. Authenticate Users
Hack 42. Build a Custom Upload Script
Chapter 7. Custom Applications
Hacks 43-50
Hack 43. Mash Up Your Photos
Hack 44. Find the Dominant Color of an Image
Hack 45. Make a Color Picker
Hack 46. Make a Motivational Poster and Other
Sw ag
Hack 47. Make a Ransom Note
Hack 48. Make a Slider Puzzle
Hack 49. Make a Photo Mosaic
Hack 50. Make a Slideshow
Index
C opyright © 2 0 0 6 O 'Reilly M edia, I nc . A ll rights res erved.
So, what exac tly did Flic kr ac c omplis h that attrac ted millions of
us ers and has an es tablis hed web c ompany c hanging the way it
does bus ines s ? T he ans wer is n't an eas y one, but s tudying how
Flic kr has taken the world by s torm c an give us s ome indic ation
of where the Web is headed.
T his book aims to help you gain a deeper apprec iation and
unders tanding of the c reativity Flic kr has made pos s ible by
s howing you s ome of the many ways people are us ing and
extending Flic kr on their own. By unders tanding Flic kr, you'll
have a better s ens e of where the Web is headed, and how you
c an partic ipate.
How to Use This Book
You c an read this book from c over to c over if you like, but eac h
hac k s tands on its own, s o feel free to brows e and jump to the
different s ec tions that interes t you mos t. I f there's a
prerequis ite you need to know about, a c ros s - referenc e will
guide you to the right hac k.
How to Run the Hacks
T he programmatic hac ks in this book run either on the c ommand
line (that's Terminal for M ac O S X folks , or the D O S c ommand
window for Windows us ers ) or as C G I s c ripts or P H P
s c ripts dynamic pages living on your web s ite, ac c es s ed through
your web brows er.
Command-Line Scripts
perl
scriptname.pl
perl
scriptname.pl '"much ado about nothing" script' 10
> perl
scriptname.pl '"much ado about nothing" script' 10
7. To s top output s c rolling off your s c reen fas ter than you
c an read it, on mos t s ys tems you c an pipe (read:
redirec t) the output to a little program c alled more:
perl
scriptname.pl
| more
perl
scriptname.pl
>
output_filename.txt
9. A nd to pour s ome input into your s c ript from a file,
s imply do the oppos ite:
perl
scriptname.pl
<
input_filename.txt
CGI Scripts
Sinc e going through every pos s ibility is beyond the s c ope of this
(or any) book, if you need help you s hould c hec k your I SP 's
knowledge bas e or c all their tec hnic al s upport department, or
as k your loc al s ys tem adminis trator.
chmod 755
scriptname.cgi
PHP Scripts
Learning to Code
C hapter 1
C hapter 2
C hapter 3
C hapter 4
C hapter 5
C hapter 6
I talic
Constant width
You s hould pay s pec ial attention to notes s et apart from the text
with the following ic ons :
I f you feel your us e of c ode examples falls outs ide fair us e or the
permis s ion given above, feel free to c ontac t us at
permis s ions @ oreilly.c om.
How to Contact Us
We have tes ted and verified the information in this book to the
bes t of our ability, but you may find that features have c hanged
(or even that we have made mis takes ! ). A s a reader of this book,
you c an help us to improve future editions by s ending us your
feedbac k. P leas e let us know about any errors , inac c urac ies ,
bugs , mis leading or c onfus ing s tatements , and typos that you
find anywhere in this book.
O 'Reilly M edia, I nc .
1 0 0 5 G ravens tein H wy N .
Sebas topol, C A 9 5 4 7 2
(8 0 0 ) 9 9 8 - 9 9 3 8 (in the U .S. or C anada)
(7 0 7 ) 8 2 9 - 0 5 1 5 (international/loc al)
(7 0 7 ) 8 2 9 - 0 1 0 4 (fax)
T he web s ite for Flickr Hacks lis ts examples , errata, and plans for
future editions . You c an find this page at:
http://hac ks .oreilly.c om
Safari Enabled
H ac ks 1 - 9
N ow, ins tead of waiting for a gathering to s hare your photos , you
c an make them available to your friends and family almos t as
s oon as you take them [Hack #6]. You c an even add the photos
to your own web s ite [Hack #9] if you want. A nd in addition to
friends and family, Flic kr c an c onnec t your photos with a wider
audienc e of people who might be interes ted in them. Sharing
photos is nothing new, but Flic kr gives you the opportunity to
s hare your photos in new ways .
To get s tarted s haring photos with Flic kr, you jus t need a minute
or two to c reate your ac c ount. Brows e to Flic kr
(http://www.flic kr.c om), and c lic k the "Sign up now! " button
s hown in Figure 1 - 1 .
When you return to Flic kr in the future, you c an c lic k the "Sign
in" link at the top of the Flic kr front page. From there, you'll s ee
the two s ign- in options s hown in Figure 1 - 2 .
T his c hapter will s how you the bas ic s of us ing Flic kr to s hare
photos , and it will take you beyond the upload form [Hack #5] s o
you c an be s haring photos like a Flic kr power us er in no time.
Hack 1. Store, Sort, and Share Your
Photos
A t its mos t bas ic , Flic kr is a web applic ation that helps you
c reate a public journal of photos . You c an upload your photos to
Flic kr and s ee them appear on a web page, with the mos t
rec ently added photo on top. But onc e you s tart playing with
Flic kr, you'll quic kly find that it's muc h more s ophis tic ated. I n
fac t, Flic kr is an open platform for s toring, arranging, s haring,
dis c us s ing, and dis c overing photos with people ac ros s the
globe.
Store
Sort
You'll find every photo you upload in your Flic kr photos tream. A
photos tream is s imply a lis t of every photo you've uploaded in
revers e- c hronologic al order, with the lates t photo you've
uploaded firs t. O nc e your photos are in your photos tream,
however, there are a number of ways you c an organize them
beyond the c hronologic al lis ting.
Tagging
Organizing
T he "V iew as s lides how" link on the front page of a s et will let
people s ee the group of photos as a Flas h pres entation. V iewers
don't even have to pres s keys or c lic k mous e buttons ; they c an
s it bac k and watc h the photos dis s olve in and out as the
pres entation automatic ally moves from one pic ture to the next.
Share
Flickr community
Flic kr works bes t when your friends and family are als o
partic ipating at the s ite. You c an add anyone with a Flic kr
ac c ount as a friend, family member, or c ontac t.
Keep in mind that the c ategory another
Flic kr member is in will determine whic h
photos of yours that pers on c an s ee if you
alter your photos ' default privac y s ettings .
You c an als o brows e a full lis t of your c ontac ts by c lic king the
P eople link at the top of any page; c lic king a name will take you
to that pers on's photos tream. Figure 1 - 8 s hows a c ontac t lis t at
Flic kr.
I f you're interes ted in a s pec ific topic , c hanc es are good that
s omeone has c reated a s pec ific Flic kr group devoted to it. You
c an brows e a full lis t of groups , organized by topic , at
http://www.flic kr.c om/groups _brows e.gne. Figure 1 - 9 s hows the
Flic kr group for Yahoo! Hacks (my previous book for O 'Reilly),
whic h you'll find online at
http://www.flic kr.c om/groups /yahoohac ks /.
Flic kr exis ts s o that you c an s hare photos , but you might not
want everyone in the world to s ee all of your photos . Your friends
would love to s ee photos of you knoc king bac k a few beers at
your favorite bar, but your bos s might frown on them. Your family
would love to s ee photos of you dres s ed up for your c ous in's
wedding, but your friends might not apprec iate your powder- blue
tuxedo. With a bit of planning, you c an make s ure that your Flic kr
photos are s hared with only the people whom you want to s ee
them (or not s hared at all).
E very photo s ent to Flic kr has a privac y s etting, and the default
s etting is P ublic . When a photo is P ublic , anyone vis iting Flic kr
c an s ee the photo. I f you want to c ontrol ac c es s to your photos
more c los ely, you c an s et them as P rivate. But the term
"P rivate" is a bit mis leading, bec aus e there are different levels
of privac y. To unders tand how the levels of privac y work, you
need to know a bit about how Flic kr c ontac ts work.
Flickr Contacts
When you mark a photo as P rivate, the ability to view the photo
is limited to you (of c ours e) and c ertain people among your
Flic kr c ontac ts . Say you want to s hare a s lightly embarras s ing
baby pic ture of yours elf with members of your family, but not the
res t of the world. Firs t, you'll need to add your family members to
your c ontac t lis t by inviting them to join Flic kr (or, if they already
have ac c ounts , brows ing to their photos tream pages and adding
them as c ontac ts ).
To invite people, brows e to your Flic kr home page and c lic k the
I nvite link at the top of the page. E nter your family members '
email addres s es and names , and des ignate their relation to you
by c hec king the box next to "T his pers on is family." C lic k Send,
and Flic kr will s end out invitations . O nc e a family member
rec eives the invitation, s he c an regis ter at Flic kr, and s he'll be
added to your c ontac t lis t as a family member.
You c an c hange a c ontac t's s tatus at any time by c lic king the
P eople link at the top of any Flic kr page. From there, navigate
through your c ontac ts and hover over the ic on of the c ontac t
you'd like to c hange. A pink box like the one in Figure 1 - 1 0 will
appear, as king if you'd like to c hange the s tatus of your c ontac t.
Setting Privacy
You c an s et the privac y s ettings for s pec ific photos at any point,
but it's bes t to do s o when you initially upload the photos to
Flic kr. Figure 1 - 1 2 s hows the privac y s ettings on the bas ic
upload form.
I f you find that you're marking every photo you upload to Flic kr
as P rivate, you c an s et this as the default privac y s etting. A t the
bottom of any Flic kr page, under the Your A c c ount heading, c lic k
the P hoto P rivac y link to s et your privac y preferenc es , as s hown
in Figure 1 - 1 4 .
Flickr will display the inf ormation that most digital cameras
embed inside a photo, and with the right tools, you can control
this data.
I f you take photos with a digital c amera, c hanc es are good that
the original files that c ome from the c amera c ontain information
about the c amera s ettings when you s napped the photos . T his
information c an inc lude the date and time, how long the s hutter
was open, the s ettings you c hos e for the s hot, and whether your
lens was zoomed in or out. T his type of information is c alled
metadata, whic h literally means data about data.
I n the days before digital c ameras , one of the bes t ways to s tore
information about a photo was by flipping over a print and
phys ic ally writing on it. I n the digital world, information about a
photo c an be embedded within the image file its elf. V iewing the
info c an help you remember how you got a great s hot, or tell
others how they c an ac hieve a s imilar effec t.
I f metadata is pres ent in your photo when you upload it to Flic kr,
you'll find your c amera make and model along with a "M ore
properties " link on the photo detail page, as s hown in Figure 1 -
15.
Camera
Expos ure
Aperture
Focal Length
I SO Speed
Orientation
Software
Artis t Name
Copyright
Viewing Metadata
Photoshop CS
O pen a photo in P hotos hop and c hoos e File File I nfo... from
the menu to dis play the metadata window s hown in Figure 1 - 1 7 .
Figure 1-17. Viewing camera metadata in
Photoshop CS
C hoos e a page of data on the left, and you'll s ee the details on
the right. T he C amera D ata 1 and 2 pages s how the tec hnic al
info about the photo embedded in the file. You c an't edit this
information within P hotos hop, but you c an view the info s o you'll
know what others will s ee onc e you've added the image to Flic kr.
I f you c lic k the D es c ription page, though, you have the option to
add a title, author, des c ription, keywords , and c opyright
information to the image metadata. Figure 1 - 1 8 s hows the
metadata entry form.
Exifer
E xifer (http://www.friedemann-
s c hmidt.c om/s oftware/exifer/index.htm) is a free program
s pec ific ally des igned to read and edit image metadata. O nc e you
open E xifer, brows e to a folder with images and highlight a
s pec ific image to s ee the metadata in the right pane, as s hown in
Figure 1 - 2 0 .
E xifer will give you the option to s ave the original metadata in a
s eparate file. You may want to do this , bec aus e there's no Save
A s ... option in E xifer, and any metadata c hanges are written into
the file.
jhead
From the c ommand prompt, c all the program and inc lude an
image file to analyze, like s o:
jhead moon.jpg
E ven though the c amera noted that the photo was taken in
2 0 0 4 , editing the metadata will tell Flic kr and the world that the
photo was really taken in 2 0 0 3 . To s ee all of the metadata
editing options in jhead, bring up the help doc umentation, like
this :
jhead -h
While not as friendly as the other programs , you might find jhead
us eful for editing the image metadata of entire folders of photos
at a time.
Hiding Metadata
I f you'd rather not s hare your image metadata with the world,
there are s ome s teps you c an take to keep the info to yours elf.
Firs t, Flic kr provides a way to turn of the "M ore properties " link
on your photo detail pages .
To hide this link, brows e to Flic kr and c hoos e the P rofile P rivac y
link under Your A c c ount at the bottom of the page. C hec k the
box next to "H ide my E XI F data? " and c lic k Save C hanges . Keep
in mind, though, that while the E XI F properties page will be
hidden from other Flic kr us ers , a determined us er will s till be
able to download the original file and extrac t the metadata.
Removing metadata from image files will
reduc e the file s ize by 5 to 1 0 kilobytes ,
s o if you're really trying to s queeze every
extra byte from your photos , removing
E XI F data will help. You won't notic e a
differenc e in upload times or Flic kr
bandwidth us age with a c hange that s mall,
though many programs (inc luding
P hotos hop) remove the data if you us e the
"Save for Web" option.
D igital photos c ome in all s hapes and s izes , bec aus e they're
taken by devic es with varying c apabilities and us ed for a number
of different purpos es . I f you're going to print a digital photo, you
want the highes t res olution pos s iblethe more pixels there are in
a photo, the better the print quality will be when trans lating that
photo to paper. I f you're jus t going to dis play an image on a
c omputer s c reen, on the other hand, you c an us e a s maller
image, bec aus e the s c reen does n't need as many pixels to
dis play a s harp image. Bec aus e Flic kr images are primarily us ed
for dis play on c omputer s c reens , you c an take advantage of that
fac t and tailor your images jus t for Flic kr by res izing them.
When you're us ing Flic kr, you don't need to think about the s ize
of an image. H owever, there are s everal reas ons why you s hould
keep image s ize in mind. P os s ibly the mos t important reas on is
c ons erving bandwidth. T he free vers ion of Flic kr allows 2 0
megabytes of trans fer eac h month, and larger image dimens ions
us ually mean a larger file (in megabytes ) to upload. I t takes
longer to upload larger photos , and you c an upload fewer photos
per month at the large s ize.
I f you don't pay attention to your bandwidth you might not ever
know you're uploading extremely large images , bec aus e Flic kr
automatic ally res izes them to a number of different s tandard
s izes . For example, all photos in your photos tream will be
dis played at a maximum of 2 4 0 pixels wide (or high, depending
on their orientation), allowing people to view many of your photos
at onc e. E ac h image is dis played at a maximum of 5 0 0 pixels at
the longes t dimens ion on its detail page, s o that viewers c an s ee
a bit more detail than was available in the photos tream lis ting.
I n fac t, if you upload a photo that's 1 ,0 0 0 pixels wide, no
viewers will s ee it at its full s ize unles s they c lic k the A ll Sizes
button on the photo detail page.
A nother reas on for res izing your images is that you might not
want other Flic kr us ers to have ac c es s to larger vers ions of your
photographs . L arge (high- res olution) vers ions of photos not only
s how more detail on the s c reen, but are als o better for printing.
So, if you'd rather not give other Flic kr members print- quality
vers ions of your photos , res izing them before you upload will
make s ure that people have ac c es s only to vers ions that look
good on a c omputer s c reen. T his will allow you, for example, to
give everyone ac c es s to s c reen- quality vers ions of your photos ,
but c harge for print- quality vers ions at your own web s ite.
Photoshop CS
O pen the image you want to res ize in P hotos hop and c hoos e
I mage I mage Size from the top menu to bring up the I mage
Size dialog. (O r, in P hotos hop E lements , c hoos e I mage
Res ize I mage Size.) C hange the units to pixels in the top
drop- down menu, and enter your des ired width, as s hown in
Figure 1 - 2 1 .
With the new width and height s et, c lic k O K to res ize your image.
C hoos e File Save A s ... from the menu, and give your newly
res ized image a new name that you'll rec ognize. (I t's always a
good idea to keep a c opy of your original photo, rather than
overwriting it, s o you c an go bac k and print the file or us e it for
s ome other reas on down the road.)
IrfanView 3.97
M ic ros oft offers a s eries of s mall, free applic ations that you c an
add to Windows XP, c alled "P owerToys ." E ac h P owerToy
performs s ome s pec ific tas k that's not inc luded with the bas ic
operating s ys tem ins tallation, and the I mage Res izer P owerToy
does jus t what you'd expec t. To get a c opy, brows e to
http://www.mic ros oft.c om/windows xp/downloads /powertoys /xppow
and s earc h for "image res izer" on the right s ide of the page.
When you c lic k Res ize P ic tures , you'll s ee a window like the one
s hown in Figure 1 - 2 4 .
O nc e you've made your c hoic e, be s ure that the "Res ize the
original pic tures " option is not c hec ked, and c lic k O K. T he
I mage Res izer will c reate new images with the s ame names , but
you'll find the words Small, M edium, L arge, WinC E , or C us tom
added to the new filenames . For example, a file c alled
s unflower.j pg would be c opied, res ized, and s aved as s unflower
(s mall).j pg if you c hos e the s mall image s ize from the menu.
iPhoto
Thinking Small
You c an now upload your newly res ized images to Flic kr, us ing
your favorite method [Hack #5]. You s hould notic e that it takes
les s time to trans fer the files , and you'll have more room in your
Flic kr ac c ount to upload files .
A ls o note that many Flic kr upload tools will automatic ally res ize
photos for you, s o be s ure to c hec k the options available to you
in your uploading tool of c hoic e.
A dding a photo to Flic kr is n't hard. I f you brows e to Flic kr, log in,
and c hoos e U pload from the menu, you'll find the upload page
[Hack #1], with s ix empty fields waiting for photos . C lic k the
Brows e... buttons next to the fields and c hoos e s ome loc al files ,
and your photos will s oon make their way from your des ktop to
Flic kr.
Batc h uploading tools s ave you time by letting you upload entire
groups of photos at onc e. L et's take a look at s ome of the
available options .
M ac us ers aren't the only ones who c an benefit from offic ial
Flic kr tools , and there's a vers ion of U ploadr for Windows
available at the Flic kr Tools page (http://www.flic kr.c om/tools /).
Be s ure to c hoos e the proper vers ion of U ploadr for your vers ion
of Windows ; download the program and double- c lic k the ic on to
s tart the ins tallation.
U ploadr for Windows is a bit more s implis tic than its M ac c ous in,
and you won't be able to add titles , c aptions , or tags until you've
trans ferred the photos to Flic kr. To trans fer photos , s imply drag
the images to the U ploadr window, as s hown in Figure 1 - 2 9 , and
c lic k the U pload... button.
To try out the wizard, brows e to any folder that c ontains pic tures
with the Windows file explorer. C hoos e "P ublis h this folder to the
Web" to s tart the wizard. I f you don't s ee the P ublis h option,
c hoos e Tools Folder O ptions ... from the menu and make
s ure the "Show c ommon tas ks in folders " option is s elec ted.
A fter you c lic k "P ublis h this folder to the Web," you c an s elec t
the photos from the folder that you want to add to Flic kr. Figure
1 - 3 1 s hows the s elec tion proc es s .
Flidget
Konfabulator
A s with Flidget, you c an s imply drag and drop an image file onto
the Flic kr U pload Widget. I n addition to tags , you c an add a title
and a des c ription and s et your privac y preferenc es before
c lic king U pload to trans fer the file, as s hown in Figure 1 - 3 3 .
I f the tools mentioned here aren't quite right for your Flic kr- flow,
you might want to inves tigate rolling your own [Hack #42] . T he
Flic kr A P I gives you programmatic ac c es s to all of Flic kr's
features , inc luding uploading photos , s o with a bit of
development you might be able to build your perfec t uploading
tool. A ls o, be s ure to look at the offic ial Tools page
(http://www.flic kr.c om/tools /) at Flic kr to find the lates t available
tools .
Hack 6. Post Pictures from Your Cell
Phone
Using Flickr's post via email f eature, you can send photos
directly f rom your cell phone while you're out and about.
I magine you're out walking around your c ity, and you notic e that
the annual fair is s etting up for its week- long extravaganza.
You'd like to s hare the news with your friends and family. You
c ould take a pic ture of the newly unloaded c arous el with your
digital c amera, walk home, trans fer the photo to your c omputer,
and then upload it to Flic kr. I f you have a c ell phone with a built-
in c amera, however, you c an take the pic ture and pos t it to Flic kr
on the s pot. H ooray for c onvergenc e!
To pos t from your c ell phone, you'll need a c ellular plan that lets
you s end photos via email. T he data- trans fer plans are us ually
$ 5 to $ 1 0 more per month than s tandard plans , or you might
have a pay- per- us e option that lets you pay for the number of
mes s ages you s end. C hec k with your c ellular s ervic e provider to
get details about s ending email from your phone. O nc e your plan
is in plac e, pos ting from your c ell phone relies on Flic kr's
"U pload- by- email" feature. M os t c amera phones c an s end any of
their photos via email. With the proper phone and plan, you
s imply need a Flic kr email addres s .
Uploading by Email
E very us er at Flic kr has a unique email addres s for uploading
pic tures . You c an find out yours by looking under Your A c c ount
at the bottom of any Flic kr page and c lic king the appropriately
titled "U pload- by- email" link. You'll s ee a page like the one in
Figure 1 - 3 4 , whic h lets you in on your s ec ret addres s .
T he "U ploading by email" page als o lets you s pec ify any tags to
automatic ally add to a photo when it's uploaded via email.
P opular tags for c ell phone us ers inc lude cameraphone, mobile,
and moblog (s hort for mobile blog). I f you're going to be taking
photos from a s pec ific loc ation with your mobile phone, you
c ould inc lude the loc ation name as an auto- tag as well.
While the page is s till up on your c omputer, grab your c ell phone
and s tart a new entry in your phone's c ontac ts lis t. I f you enter
your private Flic kr addres s now, you won't have to remember it
while you're out and about. Figure 1 - 3 5 s hows how entering the
addres s looks on a c ell phone; be s ure to add it to the email field
of a c ontac t.
Sending a Photo
So, you're out about town, armed with a c amera phone and a
Flic kr addres s s tored as a c ontac t. When you c apture the perfec t
image, you'll be s et for s haring it with the world.
When the mes s age is ready to go, c lic k Send, and your phone
will s end the mes s age through powerful c ell networks direc tly to
Flic kr. Your phone might even provide a Sending M es s age
graphic like the one s hown in Figure 1 - 3 8 to let you know the
mes s age is on its way.
Flickr Badges
Choos e colors
T he <script> tag does the work of dis playing the photos . A s you
c an s ee in the src attribute, the J avaSc ript file res ides at
http://www.flic kr.c om and dis plays photos bas ed on the
parameters pas s ed in the U RL . M any of the dec is ions you made
while running through the badge- c reation proc es s are
enc aps ulated in this U RL . For example, the count variable will be
s et to the number of photos you told the badge to dis play, and
the layout variable will be s et to v or h, depending on your c hoic e
of vertic al or horizontal layout.
I f you need to c hange your badge, try s tudying the fairly s elf-
explanatory variables in the U RL and c hanging their values . T hat
way, you c an make c hanges quic kly without running through the
whole badge- c reation proc es s again.
Flickr Feeds
E ac h Flic kr feed c ontains the 1 0 mos t rec ently added photos for
a partic ular us er, group, or tag. T he item nodes in the feed
c ontain all of the details you need to dis play the photo on a
remote s ite: the title, a link to the photo on Flic kr, and a bit of
H T M L for dis playing a thumbnail and c aption. H ere's a look at an
item in a Flic kr RSS feed (this example has been formatted for
readability; the ac tual feed inc ludes es c aped H T M L , with tags
s uc h as <p> rendered as the es c aped <p>):
<item>
<title>Ultimate Championships</title>
<link>http://www.flickr.com/photos/pb/16469233/</link>
<description>
<p><a href="http://www.flickr.com/people/pb/">pb</a> poste
<p><a href="http://www.flickr.com/photos/pb/16469233/"
title="Ultimate Championships">
<img src="http://photos10.flickr.com/16447365_40ac8021
width="240" height="161" alt="Ultimate Championships"
style="border: 1px solid #000000;" /></a></p>
<p>the women's championship game was washington vs. stanfo
</description>
<pubDate>Mon, 30 May 2005 11:01:15 -0700</pubDate>
<author>nobody@flickr.com (pb)</author>
<guid isPermaLink="false">tag:flickr.com,2004:/photo/16469233<
</item>
T he <title> and <link> elements hold the title of the photo and a
link to the photo, as you'd expec t. T he <description> element
holds the bloc k of H T M L that you c an us e on a remote s ite.
The code
#!/usr/bin/perl
# flickr_feed.pl
# Transforms a Flickr Feed into HTML
# Usage: flickr_feed.pl
use strict;
use XML::RSS;
use LWP::Simple;
T his c ode downloads the Flic kr feed and mas s ages the H T M L in
the <description> tag, removing s ome text. I t then prints eac h
item in the feed, until it hits the number s pec ified in the las t line
of the s c ript.
You c an run this c ode from the c ommand line by c alling the
s c ript like this :
perl flickr_feed.pl
C K's Flic kr A lbum M aker pres ents an online form in whic h you're
reques ted to fill out a few fields . I t then produc es either a s tatic
gallery of your photos , or a s lides how. I n both c as es C K
provides you with the H T M L c ode, s o you c an c opy it and pas te
it into your own web s ite.
Making an Album
I f you s elec t the Slides how option at the top of C K's form, it will
produc e s ourc e c ode for a very s piffy interac tive s lides how,
ins tead of a s tatic gallery. T he s lides how will look s omething like
Figure 1 - 4 4 .
T here are a few other web s ites that work in a s imilar way. A lot
of C K's s tuff either us es or is ins pired by O berkampf, a P H P
library of us eful routines for building s lides hows and galleries .
T he O berkampf web s ite
(http://www.entrauge.c om/tools /oberkampf/index.php) als o
employs an online form to c ollec t your pers onal information,
whic h it then embeds direc tly into a pers onalized c opy of the
O berkampf s ourc e c ode.
See Also
M any weblog s ys tems offer tools to help you upload and inc lude
images with your pos ts , bit you might find that Flic kr is a nic e
alternative to the s tandard photo tools . O nc e you upload a photo
to Flic kr [Hack #1], you have s everal options for inc luding that
photo in your weblog pos ts .
Blog This
Configuring a weblog
Blogger
http://www.blogger.c om
TypePad
Movable Type
WordPres s
http://www.wordpres s .org
Manila
http://www.manilas ites .c om
I f you us e a weblog tool that's not lis ted, c hec k your tool's
doc umentation to s ee if it us es one of the s upported weblog
applic ation programming interfac es (A P I s ). A n A P I allows a
third- party tool s uc h as Flic kr to add pos ts to your weblog. Flic kr
s upports the following A P I s :
Atom
BloggerAPI
MetaWeblogAPI
C hoos e your weblog from the lis t, c lic k N ext, and verify the
information on the following page. I f you don't feel c omfortable
s toring your weblog tool's pas s word with Flic kr, you c an unc hec k
the box labeled "Store your pas s word? " C lic k A ll D one, and
you'll be ready to s tart pos ting pic tures !
While the Blog T his feature at Flic kr works well for pos ting a
s ingle photo along with s ome text, it does n't work as well for
pos ting multiple photos within a s ingle pos t. A nd you might find
that your pos t layouts are s o unique that a s ingle template won't
work. I n either of thes e c as es , you'll need to write your own
H T M L to dis play images in your weblog pos ts . E ven though
you'll be doing s ome of the work on your own, Flic kr c an s till
make your life eas ier by hos ting and proc es s ing your images .
http://photos11.flickr.com/17447365_fff01711bb_o.jpg
N otic e that the U RL s tarts with a Flic kr domain and that the
filename inc ludes two alphanumeric I D s s eparated by an
unders c ore, followed by a final letter (again s eparated by an
unders c ore) before the .jpg extens ion. T hat final letter is a URL
code, whic h repres ents the s ize of a Flic kr photo; unders tanding
the c odes c an help you c reate or c hange links to different photo
s izes on the fly. H ere's a quic k look at the different photo s izes
available at Flic kr:
Large
Medium
T he M edium s ize is what you s ee on a Flic kr photo detail
page. T his s ize will be 5 0 0 pixels at its longes t
dimens ion, depending on the orientation of the photo.
T here is no U RL c ode for M edium photos , bec aus e this
is the default s ize.
Small
Thumbnail
Square
<img src="http://photos11.flickr.com/17447365_fff01711bb_m.jpg" wi
When you're writing your own H T M L , you c an c ombine multiple
images , link images to unique web pages , or c reate more
c omplex layouts than are pos s ible with Flic kr's Blog T his
feature. Figure 1 - 5 1 s hows a s ingle pos t at L iveJ ournal with
s everal photos hos ted at Flic kr.
H ac ks 1 0 - 1 4
I magine you have a pic ture of a s hirt, and you'd like to be able to
find that pic ture in the future. I f you add a few tags to the photo,
s uc h as s hirt, clothes , or fas hion, when you want to s ee that
pic ture in the future you c an s imply brows e your tags and view
all of your photos tagged with s hirt as a s eparate c ollec tion of
photos . A ls o, anyone els e interes ted in pic tures of s hirts will be
able to s ee your photo as part of the larger, global c ollec tion of
photos tagged with s hirt.
Flic kr was one of the firs t applic ations on the Web to allow
tagging of c ontent, and Flic kr members have c ome up with many
ways to us e tagging to their advantage. Some have c reated
alternate interfac es and games [Hack #11] for brows ing global
tag c ollec tions . O thers have found a way to us e tags to indic ate
the loc ation a photo was taken [Hack #12] . You c an als o us e
Flic kr's tags to c reate your own vis ualizations of how people are
us ing tags [Hack #14] .
Taking some time to think about how you describe your photos
on Flickr might help you f ind a wider audience f or your pictures.
You c an add titles and des c riptions when you upload a photo, or
later (s imply c lic k the "E dit title, des c ription, and tags " link to
the right of the photo on the detail page). You c an als o edit them
at any point by s imply c lic king the title or des c ription. Figure 2 -
1 s hows what editing a title looks like.
Figure 2-1. Editing a photo title
C lic k Save onc e you've made your c hanges , and your new title
or des c ription will be s et.
Tags
Tags are keywords you c an add to your photos . T here are two
main reas ons to add tags to your photos . T he firs t is for your
own c ategorization. I f you tag every photo of your c at that you
pos t to Flic kr with the word cat, you c an ins tantly view all of
thos e photos in a group by c lic king on your cat tag. T he other
reas on to tag photos is to take part in the larger c ommunity of
Flic kr us ers . By c lic king the global cat tag, you c an s ee other
photos that people have tagged with that keyword.
You'll als o find many photos tagged with the name of the loc ation
where the photo was taken; it might make s ens e to tag a photo
with a plac e name, es pec ially if the photo is a s hot of a s pec ific
area. (T he photo in Figure 2 - 2 was taken in O regon, but as the
photo is not s pec ific ally related to O regon in any way, an Oregon
tag was n't inc luded.)
Get suggestions
Don't spam
Notes
P ointing out a s pec ific part of a photograph is s omething we do
all the time when we're s haring print photos with people fac e to
fac e. We point out s pec ific people in a photo that s omeone els e
does n't know, or a c ritic al portion of the photo that s omeone
s hould s tudy more c los ely. But when we're s haring photos on the
Web, it's not as eas y to point out jus t a portion of a photo. T hat's
where Flic kr notes c ome in handy.
Notes are one of the mos t unique features of Flic krthey provide
the ability to annotate photos by highlighting a portion of the
photo and inc luding brief text notes about that s ec tion. A s
vis itors hover their mous e pointers over a photograph, they c an
s ee the note for a partic ular region of the photo. I t might not be
immediately apparent why you'd need to annotate a s pec ific
s ec tion of a photo when you c an inc lude extended des c riptions
and tags with eac h photo, s o let's look at s ome of the reas ons
you might want to do s o.
Collaborate
Summary
E ffec tively des c ribing your photos at Flic kr is a fairly eas y tas k,
but it's one that c an benefit from s ome forethought. T hinking
about how your photos fit with the larger c ommunity will help you
c onnec t with other Flic kr members and organize your photos
more effic iently.
Hack 11. Play with Tags
H ere are a few interac tive examples that will give you a s ens e of
how others are reus ing Flic kr images . By playing s ome of thes e
games , you'll s ee how Flic kr images c an be us ed in new ways
(and probably have s ome fun in the proc es s ).
Memry
You c an us e any tag you like, but patterns make for partic ularly
diffic ult matc hing. I f you c an't think of any tags , try bricks , leaf,
fractal, or texture.
When you're finis hed with a game, you c an c lic k on any of the
photos to view the full photo on Flic kr. A nd if you want to s hare a
partic ular game, you c an add a tag to the U RL to bring up that
tag immediately, like this :
http://www.pimpampum.net/memry/enter.php?tag=infrared
flickrTagFight
http://netomer.de/flickrtagfight/kitten.puppy.fight
Replac e the words kitten and puppy in this example with the two
tags you'd like to s ee ins tead.
When the Brows er s tarts , you'll s ee the tag you c hos e in the
c enter s urrounded by a c irc le of around 5 0 related tags . For
example, if you typed in the tag water, you'll find related tags
s uc h as waves , pool, waterfall, ocean, and river. C lic king a related
tag will put that tag in the c enter and s how further related tags in
the c irc le.
A ny tag in the c enter inc ludes a bloc k of 3 6 rec ently added
photos that have that tag. C lic king on a photo will bring up a
larger vers ion of the photo, as s hown in Figure 2 - 8 .
You can use Flickr tags to describe the exact location where you
took a photo, and then display your geographically precise
photos on a map.
geo:lat=latitude
geo:lon=longitude
geotagged
T he geotagged tag lets others know that the photo has been
given a s pec ific loc ation, and the other two tags des c ribe that
loc ation. A s you know, latitude and longitude aren't exac tly
found on every s treet s ign, s o the work involved with geotagging
is finding out your c oordinates .
For example, entering the phras e " 23rd and Lovejoy ST, Portland
OR" will give you a map of P ortland, and the latitude and longitude
for that loc ation: 4 5 .5 2 9 7 4 , - 1 2 2 .6 9 8 3 0 7 . O nc e you have the
c oordinates , you c an add your three tags to your photo taken in
that loc ation, as s hown in Figure 2 - 9 .
E ac h G P S unit will have its own method for looking at trac k logs
from an outing, s o you'll need to c ons ult your manual to s ee how
you c an find your trac ks . Figure 2 - 1 0 s hows a trac k log from a
G armin eTrex V is ta in the M apSourc e s oftware that c omes with
the unit. A s you c an s ee, eac h log inc ludes prec is e points along
the way and the time when the devic e was at eac h of thos e
points .
You c an then view the E XI F data for the photos you took with a
program s uc h as E xifer (http://www.friedemann-
s c hmidt.c om/s oftware/exifer/), as s hown in Figure 2 - 1 1 , to s ee
exac tly when you took a partic ular photo.
T his hac k has jus t s c ratc hed the geotagging s urfac e. I n the
future, as our c ell phones and c ameras bec ome loc ation- aware,
the proc es s of geotagging photos is bound to bec ome more
automated. U ntil then, a bit of manual gluing between c amera,
c oordinates , and Flic kr c an tie your photos to the loc ations
where they were taken.
Hack 13. Exploit Compound Tags
"H elp! " L eo wrote to me, "What is a good way to tag the photos
s o they c an be us ed for s c ripting purpos es ? "
Why not? C ons ider the problem here. L et's s ay L eo adds the
photo s hown in Figure 2 - 1 3 , of a graves tone c ontaining the word
PEACE, and tags the photo peace.
leol30
word
cemetery
peace
With multiple tags , it's diffic ult to know whic h one repres ents the
ac tual word in the photo. D oes the graves tone s ay peace, or does
it s ay cemetery?
oneword:peace
You'll als o need the phpFlic kr s c ripts [Hack #41] . T hes e s c ripts
als o make authentic ating other people a s nap, but you won't
need authentic ation for this hac k. You c an download thes e
s c ripts from http://www.phpflic kr.c om.
The Code
To retrieve all the "one- word" photos and their c orres ponding
words , this s c ript performs the following s teps :
1. D ownload the lis t of photos that are in the O ne Word
group.
3. Walk through the tags and find the ones with the
matc hing prefix; then, extrac t the data us ing s tring
manipulation.
<?php
// retrieveTags.php
ini_set("error_reporting ", E_ALL);
// Configuration stuff
$flickrAPIKey = "your API key";
$cachingenabled = true;
$dbUser = "user"; //database user here
$dbPass = "pass"; //database password here
$dbAddress = "localhost"; //location of database
$dbTable = "table"; //location of table, will create one if it doe
$photos = $f->groups_pools_getPhotos($group_id);
?>
<html>
<head>
<title>retrieve tags</title>
</head>
<body>
<table><tr>
<?php
$n = 0;
foreach ($photos['photo'] as $photo) {
if ($n && $n % 6 == 0)
echo "</tr><tr>";
$photos_url = $f->urls_getUserPhotos($photo['owner']);
?>
</td></tr></table>
</body>
</html>
$cachingenabled = true;
$dbUser = "user";//database user here
$dbPass = "pass";//database password here
$dbAddress = "localhost"; //location of database
$dbTable = "table";//location of table, will create one this is it
I f you do not wis h to us e c ac hing, turn it off by replac ing this
line:
$cachingenabled = true;
with this :
$cachingenabled = false;
To run the hac k, upload the edited s c ript to your web s erver and
invoke it by typing its addres s into your web brows er:
http://www.yourwebsite.com/retrieveTags.php
C ompound tags are us ed for many of the more s ophis tic ated
applic ations on Flic kr. O ne of the more well- known us es is
geotagging [Hack #12] . L ongitude and latitude c oordinates are
attac hed to photos us ing the tags geo:lon=longitude and
geo:lat=latitude, res pec tively. Sinc e thes e photos are not all
c ontained in a group pool, the additional grouping tag geotagged
is als o applied to eac h geotagged photo, s o that they c an be
c ollec ted us ing a s imple tag s earc h.
See Also
[Hack #40]
[Hack #41]
[Hack #47]
[Hack #12]
Hack 14. Make a Flickr-Style Tag Cloud
A dding a tag cloud to your web site is easier than getting a bad
haircut!
I f the illus trations in thes e next few pages look familiar, you've
s een tag c louds before. Tag clouds are c lus ters of tags rendered
with differently s ized fonts to indic ate the relative popularity of
the tags in a datas et. C lic k on any of the tags to retrieve data
matc hing that tag (s uc h as photos ).
You'll als o need the phpFlic kr s c ripts [Hack #41] (whic h als o
make authentic ating other people a s nap, although you won't
need authentic ation for this hac k). You c an download thes e
s c ripts from http://www.phpflic kr.c om.
To get s tarted, ins tall the phpFlickr s c ripts on your web s ite, as
des c ribed in [Hack #41] . T hen download and unpac k D an
Steingart's c loudTagFlic kr s c ript, whic h is available from
http://www.allthings alc es te.c om/c loudtagflic krphp/.
The Code
$cachingenabled = true;
$dbUser = "user"; //database user here
$dbPass = "pass"; //database password here
$dbAddress = "localhost"; //location of database
$dbTable = "table"; //location of table, will create one if it doe
with this :
$cachingenabled = false;
<html>
<head></head>
<body>
<center><table width=50%><tr><td>
</td></tr></table></center>
</body>
U pload both files (cloudTagFlickr.php and tes tCloudTag.php) to
your web s erver.
http://www.yourwebsite.com/cloudTagFlickr.php
I f all is right with the world and your karma, you s hould s ee
s omething like Figure 2 - 1 5 .
O nc e you get it working, try the s ec ond s c ript, whic h inc ludes
the tag c loud as part of a more c omplex web page:
http://www.yourwebsite.com/testTagCloud.php
http://www.yourwebsite.com/testTagCloud.php?name=special
http://www.yourwebsite.com/testTagCloud.php?minsize=10&maxsize=64
http://www.yourwebsite.com/testTagCloud.php?sort=random
http://www.yourwebsite.com/testTagCloud.php?sort=asc
or a des c ending s ort by s ize, whic h looks even nic er
(Figure 2 - 1 7 ):
http://www.yourwebsite.com/testTagCloud.php?color=greyscale
http://www.yourwebsite.com/testTagCloud.php?color=hotcold
See Also
[Hack #40]
[Hack #41]
Chapter 3. Viewing Photos
H ac ks 1 5 - 2 3
H ac k 1 8 . Rate P hotos
C lic king a photo in the photos tream will take you to a larger
vers ion of the photograph on a photo detail page, as s hown in
Figure 3 - 2 .
Sets are another important type of page at Flic kr. Sets are groups
of photographs that a photographer has put together for eas y
viewing. Figure 3 - 3 s hows a s et c alled "L ittle P ups " by one of
the authors .
T his c hapter will take you beyond the bas ic s of Flic kr photo
viewing, into more advanc ed ways of enjoying photos available
at Flic kr. From integrating Flic kr photo s earc h with your brows er
[Hack #15] to us ing Flic kr photos as a s c reens aver [Hack #22],
you'll find ways to c onnec t with photos you might not have found
by s imply wandering the gallery.
Hack 15. Add Flickr Search to Firefox
I f you don't find the perfec t Flic kr s earc h at the M ozilla page, it's
fairly eas y to build your own s pec ialty Flic kr s earc h and add it to
your lis t of available s earc h engines . T his hac k s hows you how.
Flickr Search
http://www.flickr.com/photos/search/tags:needle%2Chaystack/tagmode
N otic e that the tags are s eparated by the s ymbol %2C, the U RL-
enc oded vers ion of a c omma. tagmode:any lets the s earc h know
you want to matc h any of the tags mentioned ins tead of all of the
tags mentioned. A rmed with this knowledge, you c an put
together your own Firefox quic k s earc h.
The Code
Bec aus e Flic kr s earc h res ult U RL s are formatted a bit differently
from the res ult U RL s of many other s earc h engines , the Firefox
quic k s earc h format c an't s end queries to Flic kr direc tly. But
that s houldn't s top a Flic kr hac ker from adding a quic k s earc h
entry. A bit of J avaSc ript c an do s ome trans lating, but for that
you'll need a quic k Flic kr s earc h proxy s c ript.
C reate a text file c alled flickr-s earch.htm and add the following
c ode:
<html>
<head>
<title>Flickr Proxy</title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
// Find the tags
var esign = document.URL.lastIndexOf('=');
var tags = document.URL.substring(esign+1);
T his c ode grabs the inc oming query from a Firefox s earc h and
formats a proper s earc h res pons e U RL for Flic kr. Spac es in the
s earc h are trans formed into c ommas , jus t as they are on Flic kr,
and the s earc h mode (matc h any or all tags ) is s et here as well.
N ote that the variable query holds the tags c oming in on the
c ommand line and the s earc h mode, tagmode:any. You c an c hange
tags: to text: if you'd rather s earc h titles , des c riptions , and tags ,
but if you do, be s ure to als o c hange the mode to one of the text
options : s pec ify sort:relevance or sort:interesting, or leave out
the sort option to s ort by mos t rec ent.
<SEARCH
version="7.1"
name="Flickr Tags Search"
description="Search for photos by tag at Flickr!"
method="GET"
action="http://www.example.com/flickr-search.htm" >
</search>
A s you c an s ee, this file begins with an opening <SEARCH> tag that
holds the name of the s earc h and a brief des c ription. Be s ure to
point the action attribute to your Flic kr proxy U RL . T he <input>
tag lets Firefox know that the value s hould c ome from us er input,
and that it s hould be added to the ac tion U RL .
N ame the file flickr-tags .gif or flickr-tags .png, and c opy it to the
s earchplugins direc tory. T he next time you s tart Firefox, you
s hould s ee the Flic kr ic on next to the new s earc h engine.
T his legal ambiguity is one of the reas ons that the nonprofit
group C reative C ommons (C C ) has made s everal alternative
lic ens es available to artis ts who want to lic ens e their work in
more s pec ific ways than a general c opyright provides . For
example, you c an make your work available to anyone who wants
to us e your photos on the c ondition that they're us ed for
nonc ommerc ial purpos es , but you c an s till require payment for
any c ommerc ial us e. T his means s omeone c an freely us e one of
your photos lic ens ed in this way for, s ay, a s c hool report, but
he'd need to pay you for your photo if you he were c ompiling a
book he intended to s ell. With a C reative C ommons lic ens e,
everyone knows exac tly how you would like your work to be
us edor not us ed.
Understanding CC Licenses
Attribution
Non-Commercial
Share Alike
A ttribution
A ttribution- N oD erivs
T he other lic ens es work in a s imilar way. O nc e you know the four
c onditions , you c an quic kly determine how the photographer
would like you to us e her work by looking at the lic ens e.
A s you brows e photos on Flic kr, you're bound to run into s ome of
the thous ands of images that are C C - lic ens ed. Keep your eye
out for the C reative C ommons logo on photo detail pages .
I f you're s pec ific ally looking for photos you c an us e in your own
projec ts , brows e to the Flic kr C reative C ommons page
(http://www.flic kr.c om/c reativec ommons /). You'll find rec ently
added photos lis ted by lic ens e type, as s hown in Figure 3 - 9 .
Flickr of f ers RSS and A tom news f eeds of much of its data,
making it easy to keep track of your f avorite people, groups,
and tags.
N ews feeds have revolutionized the way people read s ites on the
Web. I ns tead of brows ing hundreds of pages ac ros s the Web
every day, you c an us e s oftware c alled news readers to s ubs c ribe
to news feeds and dis play any new information in a friendly,
c ons is tent format.
T he folks at Flic kr have rec ognized the demand for news feeds
and have made mos t of the data you s ee on the web s ite
available in a number of different feeds . For example, if you want
to trac k a partic ular photographer, you c an add that pers on's
photos tream feed to your news reader and s ee any new photos he
pos ts without ever vis iting Flic kr.
Flickr Feeds
By far, the eas ies t way to add a feed to your news reader is by
c opying the U RL from the bottom of a Flic kr page. I f you pay
attention to the feed U RL s , though, you may be able to c ons truc t
your own Flic kr feed U RL s in les s time than it would take to
brows e to the appropriate pages and c opy the links .
Members
http://www.flickr.com/services/feeds/photos_public.gne?id=insert m
You c an find the N SI D for any partic ular member (inc luding
yours elf) with jus t a little bit of works ee [Hack #24] for details .
You c an als o keep tabs on your c ontac ts ' photos with a Flic kr
feed. I f you'd rather s ee photos from your c ontac ts in your
news reader ins tead of going to your c ontac ts page
(http://www.flic kr.c om/photos /friends /), you c an s ubs c ribe to a
U RL of the following format:
http://www.flickr.com/services/feeds/photos_friends.gne?user_id=in
Groups
You c an s ubs c ribe to the group photo pool for any given group
with a U RL like the following:
N otic e that ins tead of the group N SI D , the photo pool feed us es
the group name. You c an find the group U RL name by examining
the U RL of the group home page. For example, the Flic kr H ac ks
group is available at:
http://www.flickr.com/groups/flickrhacks/
You'll find the group name (in this c as e, flickrhacks) at the end of
the U RL , after /groups/.
Tags
To s ubs c ribe to all photos tagged with a partic ular keyword, you
c an us e the following U RL format:
http://www.flickr.com/services/feeds/photos_public.gne?tags=insert
I magine you're interes ted in photos of the moon and you want to
keep trac k of any photos that flow through Flic kr that are tagged
with moon. You c an s imply ins ert the tag and s ubs c ribe to the
feed, and you won't mis s any new photos .
http://www.flickr.com/services/feeds/photos_public.gne?tags=moon,s
N ote that multiple tags are an OR matc h, meaning the feed will
s how photos tagged with moon or s un. U nfortunately, Flic kr
does n't offer AND matc hes in this feed, but you c an always build
your own feed [Hack #20] with the A P I .
Flickr news
While not direc tly related to Flic kr photos and dis c us s ion, you
c an als o s ubs c ribe to news s ourc es about Flic kr its elf. You'll find
RSS feeds for the Flic kr Blog
(http://feeds .feedburner.c om/Flic krblog/), the Flic kr H elp Forums
(http://www.flic kr.c om/forums /help/feed/? format=rs s _2 0 0 ), and
the Flic kr N ews and D evelopment C hange L og
(http://flic kr.c om/news _feed.gne?
dev=1 &news =1 &format=rs s _2 0 0 ).
Reading Feeds
I f you don't already have a favorite news reader, you'll need to
c hoos e one before you c an s ubs c ribe to Flic kr feeds . A
news reader c an be an applic ation you download or a web s ite you
vis it. H ere's a look at s ome popular news readers and how they
work with Flic kr feeds .
My Yahoo!
Bloglines
NetNewsWire
N ews feeds are being baked into the fabric of many applic ations ,
and you might be able to s ubs c ribe to Flic kr feeds from within
your favorite web brows er or email c lient. For example, the
Firefox web brows er (http://www.mozilla.org/produc ts /firefox/)
s upports L ive Bookmarks . A s you brows e around Flic kr with
Firefox, look for an orange L ive Bookmarks ic on in the lower-
right c orner of the brows er window. C lic k the ic on to s ee your
s ubs c ription options . O nc e s ubs c ribed, you'll s ee the titles of
new pos ts or photos in your Bookmarks menu.
See Also
[Hack #20]
Hack 18. Rate Photos
Flic kr's c reators have dis tinc tly c hos en not to inc lude
ratings pos s ibly to avoid turning it into a c ompetition. E very
photo has value to s omeone, and they might have felt that a
ratings s ys tem was n't the atmos phere they wanted to provide.
I ns tead of ratings , Flic kr provides a way for you to mark c ertain
photographs you s ee as "favorites ."
A bove any photo on the photo detail page, you'll find a button
that s ays "A dd to Favorites ." C lic k the button, and you'll
es s entially bookmark that pic ture s o that you c an view it
anytime in the future. To s ee all of your favorites on one page, as
s hown in Figure 3 - 1 6 , c lic k the "Your favorites " link on your
Flic kr home page.
J us t bec aus e Flic kr does n't offer ratings does n't mean that you
c an't take part in a ratings s ys tem, though. A n applic ation c alled
flic kRate by N ic olas H oizey lives a parallel life alongs ide Flic kr
and gives Flic kr us ers a way to rate the photos they s ee.
flic kRate als o gives you a look at the highes t- rated photos ,
determined by people us ing flic kRate.
Rating Photos
A s imple option that will work for any brows er is the "flic kRate
this ! " bookmarklet. D rag the "flic kRate this ! " link to the links
toolbar on your brows er to ins tall the bookmarklet. T hen, c lic k
the bookmarklet from any Flic kr photo detail page to open a
flic kRate pop- up window like the one s hown in Figure 3 - 1 8 . I n
the new window, c hoos e your ratings and c lic k Rate, and your
ratings will be s aved at the flic kRate web s ite.
I f you us e the Firefox web brows er and have the G reas emonkey
plug- in (http://greas emonkey.mozdev.org) ins talled, you c an us e
the flic kRate G reas emonkey s c ript, whic h integrates ratings
direc tly into Flic kr. C lic k the G reas emonkey s c ript link from the
flic kRate tools page and c hoos e Tools I ns tall T his U s er
Sc ript... from the Firefox menu. With the s c ript ins talled, brows e
to any Flic kr photo detail page, and you'll s ee the flic kRate form
underneath the photo, as s hown in Figure 3 - 1 9 .
Browsing Ratings
H alf the fun of us ing flic kRate is s eeing how other us ers have
rated photographs . A s you c an s ee on the flic kRate home page
in Figure 3 - 1 7 , the s ite lis ts the top- rated photos in the three
rating c ategories . You c an als o c lic k the Brows e link at the top of
the home page to s ee photos that have been rated by other
us ers .
Flickr Mobile puts Flickr on your cell phone, and once it's in your
hand, you can use Flickr on the go.
O nc e you've got things working, fire up your mobile web brows er,
point your phone to http://www.flic kr.c om/mob/, and log in. You
s hould s ee the Flic kr M obile home page s hown in Figure 3 - 2 0 .
Visual Dictionary
I magine you find yours elf in Tokyo, no c abs in s ight, and you
need to get ac ros s town. I f you knew J apanes e you c ould eas ily
as k s omeone where you c ould c atc h a c ab, but with the language
barrier, you c ould be s tuc k in tough s pot. O ne option is to bring
up the Flic kr V is ual D ic tionary on your phone by firing up its web
brows er and pointing it to
http://s teeev.f2 o.org/flic kr/s earc h.php? mode=mobile. Type in
the word taxi, and you'll find a number of images on Flic kr tagged
with the word taxi, as s hown in Figure 3 - 2 2 . With a pic ture of a
taxi in your hand, c hanc es are you c an get your mes s age
ac ros s .
The Code
<?php
// t.php
// A quick mobile search for Flickr that you can use
// as a universal translator while traveling. Search
// for a word you don't know how to say in a foreign
// language on Flickr, and point to a picture of it.
//
// You can get an API key and read the full documentation
// for the Flickr API at http://www.flickr.com/services/api/
</body>
</html>
T his s c ript pres ents a s ingle form field where you c an type a
s ingle tag, or a number of tags s eparated by c ommas . T he s c ript
c ontac ts the Flic kr A P I us ing the flickr.photos.search method
and dis plays the photos in the res pons e five images at a time.
E ac h image is linked to a larger vers ion of the image, s o you c an
zoom in if you find the perfec t pic ture.
http://www.example.com/t.php
Custom Feeds
Flic kr offers a number of news feeds for mos t of the data you'll
find on the s ite, but you might run into times when you want to
build a c us tom RSS feed that Flic kr does n't provide. H ere's a
quic k look at s ome s ituations where you might want a c us tom
feed:
T his hac k pres ents a very bas ic way to build a c us tom Flic kr
feed with P erl. You c an us e the c ode as a s tarting point for
c reating your own c us tom feeds to trac k your favorite Flic kr
data.
The Code
You'll need to make s ure you have two nons tandard P erl modules
before you begin: LWP::Simple
(http://s earc h.c pan.org/~gaas /libwww- perl-
5 .8 0 3 /lib/LWP /Simple.pm) c ontac ts the A P I , and XML::Simple
(http://s earc h.c pan.org/~grantm/XM L- Simple-
2 .1 4 /lib/XM L /Simple.pm) pars es the res pons e. You'll als o need
to add your N SI D and Flic kr A P I key, both of whic h you c an find
at the Flic kr A P I s ite (http://www.flic kr.c om/s ervic es /api/).
#!/usr/bin/perl
# flickr_contact_feed.pl
# Builds a custom RSS feed of contacts' photos for a
# given Flickr user NSID.
#
# You can get an API key, find your NSID, and read the
# full documentation for the Flickr API at:
#
# http://www.flickr.com/services/api/
use strict;
use LWP::Simple;
use XML::Simple;
You c an run the c ode from a c ommand prompt, piping the res ults
to an XM L file:
U pload the output file to a public ly addres s able web s ite and
note the U RL , whic h s hould look like this :
http://www.example.com/flickr_contact_feed.xml
With your U RL in hand, you c an add the new feed to your favorite
news reader. Figure 3 - 2 4 s hows the feed in the Bloglines web-
bas ed news reader.
T his hac k s hould give you a s tarting point for building your own
feeds bas ed on data from the Flic kr A P I . With a few minutes of
s c ripting, you c an have muc h more c ontrol over your Flic kr
s ubs c riptions .
See Also
[Hack #17]
[Hack #7]
Hack 21. Set Random Desktop
Backgrounds
Use the Flickr A PI to spin a virtual roulette wheel, and let f ate
choose your desktop background image based on a Flickr tag you
specif y.
P eople love to c hange their des ktop bac kgrounds . I t's one of the
firs t s kills that new c omputer us ers learn, and even old c omputer
pros tend to fiddle with their des ktop bac kground images on a
fairly regular bas is . Brows ing through the ais les of your loc al
c omputer s hop, you'll find C D s full of s c enic imagery that you
c an us e as des ktop bac kground pic tures . But why s hell out
money for c us tom bac kgrounds when you c an us e Flic kr as your
s ourc e for bac kground images ?
A s you're brows ing around Flic kr, you might s pot an image you'd
like to us e as a des ktop bac kground. But if you're like mos t
people, your des ktop is s et at a res olution of 1 0 2 4 x 7 6 8 pixels
or higherquite a bit bigger than the 5 0 0 - pixel- wide images you
s ee at Flic kr. I f you s tretc h the image to fit your des ktop, you
may end up with a blurry, dis torted mes s , rather than the s c enic
vis ta you were hoping for.
L uc kily, many people don't res ize their images [Hack #4] before
they upload them to Flic kr, and you c an often find larger vers ions
of the images you s ee at Flic kr by c lic king the A ll Sizes button
on a photo detail page (Figure 3 - 2 5 ).
Figure 3-25. The All Sizes button on a Flickr
photo page
C lic king the A ll Sizes button takes you to the "A vailable s izes "
page, whic h defaults to s howing you a large vers ion of the image,
as s hown in Figure 3 - 2 6 .
The code
A dd the following c ode to a file c alled Flickr_Background.vbs :
'-----------------------------------------------------
' Flickr_Background.vbs
'
' Finds a random image via the Flickr API and
' sets it as the desktop background image.
'
' This script depends on Image Magick, which you
' can download here:
'
' http://www.imagemagick.org
'
' Edit the following line to change the "theme" of
' your background. Double-click this file to run it.
'-----------------------------------------------------
strTag = "cityscape"
'-----------------------------------------------------
' Your Flickr API key
'-----------------------------------------------------
Const API_KEY = "insert your Flickr API key"
'-----------------------------------------------------
' Using the query, find a random image via Flickr
'-----------------------------------------------------
'Construct a Flickr search query
strReqURL = "http://www.flickr.com/services/rest/" & _
"?method=flickr.photos.search" & _
"&api_key=" & API_KEY & _
"&tags=" & strTag & _
"&tag_mode=all" & _
"&per_page=200"
End If
'-----------------------------------------------------
' Save the image locally to the root c:\ folder
'-----------------------------------------------------
' MsgBox("Downloading " & strImageTitle & "...")
strImageFile = Replace(strTag,",","_")
Set fs = CreateObject("Scripting.FileSystemObject")
Set xmlhttp = CreateObject("Msxml2.SERVERXMLHTTP")
xmlhttp.Open "GET", strImageURL, false
xmlhttp.Send(Now)
'-----------------------------------------------------
' Convert the JPEG to a bitmap
'-----------------------------------------------------
Set Converter = CreateObject("ImageMagickObject.MagickImage.1")
Converter.Convert "c:/" & strImageFile & ".jpg", "c:/" & strImageF
Set Converter = Nothing
'-----------------------------------------------------
' Set the newly created bitmap to background
' and refresh
'-----------------------------------------------------
strRegRoot = "HKEY_CURRENT_USER\Software\Microsoft\" & _
"Internet Explorer\Desktop\General\"
strRegRoot2 = "HKEY_CURRENT_USER\Control Panel\Desktop\"
Before you run the s c ript, make s ure you unders tand the ris ks .
T his will replac e your c urrent des ktop bac kground with a random
image from Flic kr, s o be s ure you have a bac kup of your c urrent
des ktop bac kground image before you proc eed; otherwis e, you
might los e it forever.
When you're ready to run the s c ript, double- c lic k the s c ript file
or run it from the c ommand line:
Flickr_Background.vbs
You s hould s ee your des ktop bac kground c hange. I f you're not
happy with the image, run the s c ript again. You c an keep running
the s c ript until you s ettle on s omething you likefor example, the
c itys c ape in Figure 3 - 2 7 .
Windows us ers aren't the only ones who c an experienc e the fun
that is random des ktop bac kgrounds . I f you jus t us e M ac O S X
to brows e the Web and do a bit of word proc es s ing, you might not
be aware that there's a powerful U nix- bas ed operating s ys tem
under the hood. I n fac t, in addition to the M ac s c ripting
language, A ppleSc ript, M ac O S X s hips with P erl ins talled. T his
hac k takes advantage of both P erl and A ppleSc ript to bring
s ome randomnes s to your des ktop.
The code
Before you begin, you'll need to ins tall a c ouple more P erl
modules . A s with many other P erl examples in this book, you'll
need LWP::Simple (http://s earc h.c pan.org/~gaas /libwww- perl-
5 .8 0 3 /lib/LWP /Simple.pm) and XML::Simple
(http://s earc h.c pan.org/~grantm/XM L- Simple-
2 .1 4 /lib/XM L /Simple.pm) to make Flic kr A P I reques ts and pars e
the res pons es .
O nc e the prerequis ites are ins talled, add the following c ode to a
file named flickr_background.pl:
#!/usr/bin/perl
# flickr_background.pl
# Accepts a tag and sets a Mac desktop background
# with an image from Flickr that has that tag.
# Usage: flickr_background.pl <tags>
use strict;
use LWP::Simple;
use XML::Simple;
use Mac::AppleScript qw(RunAppleScript);
A s you c an s ee, the las t few lines of the s c ript are A ppleSc ript
ins ide of P erl. T he firs t line of A ppleSc ript s ets a preexis ting
image as the bac kground, and the s ec ond line s ets the newly
c reated file as the bac kground. T his ens ures that the
bac kground will refres h when you run the s c ript.
You c an run the s c ript from the c ommand line, adding a des ktop
theme, like this :
perl flickr_backgound.pl
tags
Running the s c ript with the countrys ide tag, for example, will s et
your bac kground to s omething that looks like Figure 3 - 2 8 .
A long with des ktop bac kgrounds [Hack #21], s c reens avers have
always been a feature of pers onal c omputers that people feel
c omfortable c hanging, tweaking, fiddling with, and hac king for
fun. A nd with a bit of s c ripting, you c an c reate a photo s lides how
s c reens aver with more meaningful images than flying toas ters .
T his hac k relies on the photo s c reens avers that s hip with
Windows XP and M ac O S X. E ac h s c reens aver lets you s pec ify a
direc tory on your c omputer that c ontains images , and dis plays
thos e images on your s c reen during your idle c omputer
moments . T his hac k us es P erl and the operating s ys tem's
s c heduling features to s ubs c ribe to a Flic kr RSS feed [Hack
#17] with images . A t regular intervals , the s c ript downloads all
of the images from a s pec ific feed into a s pec ial direc tory that
your s c reens aver c an us e.
The Code
C opy the c ode to a file c alled flickr_s creen.pl, and put it in a loc al
folder path where the images will be s tored. O n Windows XP, you
s hould s pec ify a drive and folder, s uc h as C:\FlickrScreen. O n M ac
O S X, you'll want to s pec ify a full path, s uc h as
/Us ers /pb/Photos /FlickrScreen.
You'll als o need to s pec ify one of the many Flic kr RSS feeds
available on the s ite. G roup photo pools work es pec ially wellif
you need a feed to tes t, try the Kite A erial P hotography group
pool feed at
http://www.flic kr.c om/groups /kiteaerialphotography/pool/feed/?
format=rs s _2 0 0 . Remember that the c ode is des igned to read
RSS 2 .0 feeds only, s o be s ure to c hoos e the c orrec t format as
you're s c outing feeds ac ros s Flic kr.
#!/usr/bin/perl
# flickr_screen.pl
# Downloads images in a Flickr RSS feed into a local folder
# you can use for a screensaver.
use strict;
use LWP::Simple;
use XML::Simple;
T his c ode reads the feed you s pec ified and downloads the
images s pec ified by eac h U RL in the <media:content> element
within eac h <item> in the feed. T his is the larges t s ize for the
image available at Flic kr. A s it downloads eac h photo, the s c ript
prints the photo title, the photographer name, and a link to the
photo detail page to s tandard output. You c an us e this to log
your downloads and go bac k to find and perhaps c omment on
partic ularly interes ting photos you s ee.
Running the Hack
On Mac OS X
perl flickr_screen.pl
crontab -e
T his opens your s c heduled tas ks for editing. To run the s c ript
every day at 8 a.m. and keep a log of the photos the s c ript
downloads , you c ould enter s omething like this :
Keep in mind, though, that the log file will fill up as the s c ript
runs every day. You might want to periodic ally open the log and
delete old entries .
Be s ure to inc lude your own paths for the files . cron is a bit
c ryptic , but it works well for s etting rec urring bac kground tas ks .
N ow that the job is s et, you c an forget about the s c ripting and let
flickr_s creen.pl download photos from Flic kr on a regular bas is .
When the s c ript runs , it will s ave information about the photos it
finds to s creenlog.txt, and you c an us e this information to trac e
an interes ting photo bac k to its detail page at Flic kr.
On Windows XP
Flickr Central f or TiVo's Home Media Engine lets you view Flickr
photos on your television.
M ore and more, we s hare digital vers ions of the pic tures we take.
While it's eas y to pas s around printed photos in any s etting,
s howing digital photos to friends and family c an be tric kier. M os t
c omputers are s et up for one us er at a time, and it's not always
eas y to c rowd a bunc h of people around the monitor.
From the main T iVo menu, c hoos e M us ic , P hotos & M ore. You
s hould s ee the option for Flic kr C entral at the top of the page.
Selec t Flic kr C entral to bring up the initial menu s hown in Figure
3 -3 3 .
I f you c lic k the info button, you'll get a s c reen that inc ludes the
title, the des c ription, and the name of the Flic kr member who
pos ted the photo, as s hown in Figure 3 - 3 6 .
H ac ks 2 4 - 2 9
H ac k 2 7 . M ap Your C ontac ts
T his c hapter will s how you how to add c ontac ts at Flic kr and
follow their ac tivity both on and off Flic kr. You'll find out how to
trac k your friends ' favorite photos [Hack #25], vis ualize where
your Flic kr friends are loc ated [Hack #27], and even c ompile a
lis t of your Flic kr c ontac ts ' web s ites [Hack #29] .
By extending the s oc ial features of Flic kr, you'll dis c over s ome
new things about your Flic kr c ontac ts and s ee their photos in a
new light.
Hack 24. Add and Track Contacts
Your Flic kr c ontac t lis t repres ents the other Flic kr members that
you want to keep trac k of. I f you add your friends , family, and
other photographers you admire to your lis t, keeping up with
their new photos is a s nap.
Adding Contacts
A s you explore photos on Flic kr, you might s pot a partic ular
photographer whom you'd like to keep up with as s he adds new
photos . To add any Flic kr us er to your c ontac t lis t, you firs t need
to get to that us er's photos tream.
From any photo's detail page, look for a byline in the upper- right
c orner. T he byline will s ay, "U ploaded on [date] by [member]."
C lic king the member's name brings you to her photos tream. A t
the top of the photos tream you'll s ee a link to add that member
as a c ontac t. C lic k the link, mark her as a friend or family
member if you want, and then c lic k O K. T hat member will now be
lis ted among your c ontac ts .
Keep in mind that adding s omeone as a
Flic kr c ontac t is a one- way operation. I f
you add s omeone to your c ontac t lis t, you
won't automatic ally appear on her c ontac t
lis t; s he'll rec eive a notific ation that
you've added her, but s he'll have to
manually add you as a c ontac t if s he wants
to.
I f you want to add s omeone to your c ontac t lis t who is n't yet a
member, you c an s end an email invitation. C lic k I nvite from the
top of any Flic kr page to bring up the I nvitation page s hown in
Figure 4 - 1 .
Rec ent ac tivity feeds are typic ally us ed to keep tabs on one's
own photos , but you c an us e thos e feeds to s ee rec ent ac tivity
with your c ontac ts ' photos , too. T his will let you know whic h of
your c ontac ts ' photos are getting the mos t c omments , and what
people are s aying about them.
To s tart reading others ' rec ent ac tivity feeds , you need to know
a bit about Flic kr member I D s . I n addition to the member I D you
s ee on a us er's photos tream (e.g., pb), every Flic kr member has
an internal N SI D an alphanumeric s tring that repres ents that
us er behind the s c enes (e.g., 33853652177@N01). O nc e you
have an N SI D in hand, you c an build your own rec ent ac tivity
feed U RL .
http://www.flickr.com/messages_write.gne?to=33853652177@N01
http://www.flickr.com/recent_comments_feed.gne?id=insert NSID&form
See Also
[Hack #17]
Hack 25. Track Your Friends' Favorites
With a weblog tool called Blosxom and some extra Perl, you can
set up a page to show your Flickr contacts' f avorite photos.
I f you find this a bit c umbers ome, ins tead of viewing all of your
friends ' favorites pages individually and looking for new photos ,
you c an let s ome s c ripting as s emble them for you. You'll need to
do s ome work to put the piec es into plac e, but in the end you'll
have a web page that automatic ally s hows any photos your
c ontac ts mark as favorites . Watc hing your friends ' favorites is a
fun way to s ee photos that are interes ting to your c irc le of
c ontac ts , and you c an us e the page to be s ure you're not
mis s ing great photos .
O ne key to Blos xom's s implic ity is that the s ys tem s tores pos ts
as text files in the files ys tem. T here's no need to have ac c es s to
a databas e or unders tand how to ac c es s a databas e.
To add pos ts to a Blos xom weblog, you s imply c reate a text file
in the proper loc ation. Blos xom rec ognizes the new file and
plac es the text c ontents of the file at the top of the weblog.
T hus , to c reate an automated weblog, you need a s c ript that c an
automatic ally write text files .
The Code
T his P erl s c ript finds all of the c ontac ts for a s pec ific Flic kr us er,
finds thos e c ontac ts ' favorite photos , and writes the H T M L to
dis play the photos as text files .
You'll need a few nons tandard P erl modules before you c an run
the s c ript. T he firs t is Flickr::API
(http://s earc h.c pan.org/~iamc al/Flic kr- A P I /lib/Flic kr/A P I .pm), a
module that makes working with the Flic kr A P I a s nap. T he
s ec ond is XML::Parser::Lite::Tree::XPath
(http://s earc h.c pan.org/~iamc al/XM L- P ars er- L ite-Tree- XP ath-
0 .0 2 /XP ath.pm), a module that helps navigate the Flic kr A P I 's
res pons e XM L .
C reate a text file c alled getFavorites .pl and add the following
c ode. Be s ure to inc lude your own Flic kr N SI D and A P I key
(available at http://www.flic kr.c om/s ervic es /api/) and the
abs olute path to your Blos xom direc tory, inc luding a trailing
s las h.
#!/usr/bin/perl
# getFavorites.pl
#
# Find out which photos your Flickr contacts are
# marking as favorites. This script contacts the
# Flickr API, gets a list of your contacts, and
# finds their favorite photos. You can get a Flickr
# API key and look up your Flickr NSID at:
#
# http://www.flickr.com/services/api/
#
# This script works in conjuction with the weblog
# system Blosxom to display the photos. You can
# download Blosxom and find out how to install it at:
#
# http://www.blosxom.com/
#
# Usage: getFavorites.pl
use strict;
use Flickr::API;
use Flickr::API::Response;
use XML::Parser::Lite::Tree::XPath;
my $response = $api->execute_method('flickr.contacts.getPublicList
'user_id' => $nsid,
});
T his s c ript c reates a direc tory for every Flic kr member in your
c ontac t lis t. Be aware that if you have 3 0 0 c ontac ts , the s c ript
will c reate 3 0 0 direc tories on your s erver. I n eac h direc tory, the
s c ript will write one text file for every favorite photo from that
c ontac t. T he text file inc ludes the title of the photo and a bit of
H T M L to dis play the photo. E ac h bit of H T M L inc ludes a link to
the original photographer's photos tream, and to the c omplete
lis t of favorites by the pers on who marked the photo as a
favorite. Blos xom handles the work of organizing the mas s of
folders and text files into s omething c oherent.
To run the s c ript, s imply c all it from a c ommand line like this :
perl getFavorites.pl
T he firs t time you run the s c ript, it will generate text files for
every favorite photo it c an find. Flic kr does n't provide dates for
when a photo was marked a favorite, s o there's no way to
bac kdate photos as marked as favorites on a c ertain date. T his
means that when Blos xom initially dis plays the lis t, it won't be
very meaningful. You'll s imply s ee potentially hundreds of photos
under the s ame date heading. But as you run the s c ript in the
future, any new favorite that's dis played will be noted with the
time it was found as a favorite.
http://www.example.com/blosxom.cgi?flav=rss
Blos xom is a very hac kable s ys tem, and there are dozens of
plug- ins available that c an add even more features to your
automated weblog. For example, a plug- in c alled categorylis t c an
print a lis t of all the folders under the Blos xom direc tory. With
this hac k, that means you c ould have a lis t of all your c ontac ts
running down the s ide of the page, and c lic king one c ontac t's
name would give you jus t that pers on's favorites on one page, as
s hown in Figure 4 - 6 .
Figure 4-6. Flickr friends' favorites sidebar
V is it the Blos xom plug- in regis try at
http://www.blos xom.c om/plugins / for a look at s ome of the other
available plug- ins .
Hack 26. Find Your Friends' Favorite
Tags
With some Perl and the Flickr A PI, you can see which tags are
most popular among your contacts.
The Code
With thos e two modules in plac e, c opy the following c ode to a file
c alled friends _tags _lis t.pl. A dd your N SI D and Flic kr A P I key
(both of whic h you c an find at the Flic kr A P I s ite,
http://www.flic kr.c om/s ervic es /api/) to the c ode.
#!/usr/bin/perl
# friends_tags_list.pl
#
# Find out which tags your Flickr contacts are
# using most often. This script contacts the
# Flickr API, gets a list of your contacts, and
# finds their most popular tags. The script then
# adds up the totals and lists the tags by the
# most popular. You can get a Flickr
# API key and look up your Flickr NSID at:
#
# http://www.flickr.com/services/api/
#
# Usage: perl friends_tags_list.pl
use strict;
use Flickr::API;
use Flickr::API::Response;
use XML::Parser::Lite::Tree::XPath;
my $response = $api->execute_method('flickr.contacts.getPublicList
'user_id' => $nsid,
});
You'll s ee your c ontac ts ' mos t popular tags , along with the
number of times eac h tag has been us ed by your c ontac ts . You
might learn s ome things about your friends that you didn't know
already, and you might find s ome tags that you c an s tart us ing
as well.
Hacking the Hack
I f you want to dis play your c ontac ts ' tags in a tag map with
relative font s izes s imilar to the Tags page at Flic kr, you c an
tweak this s c ript a bit to output H T M L ins tead of text. Replac e
everything after the # --- Begin Output --- c omment with the
following c ode:
T his new c ode s orts the tags alphabetic ally ins tead of by the
number of times eac h tag has been us ed by your c ontac ts . T he
s c ript then generates an H T M L page, giving eac h tag a font s ize
bas ed on the number of times it has been us ed. Run the c ode in
the s ame way, but s end the output to an H T M L file, like this :
O pen friends _tags .html in a brows er, and you'll s ee a lis t of tags
like the one in Figure 4 - 8 .
By combining the Flickr A PI and the Google Maps A PI, you can
see how your Flickr contacts are dispersed throughout the
world.
Geocoding a Location
http://maps.google.com/maps?q=Corvallis,%20OR&output=js
N ote that the s pac e in the loc ation has been enc oded as %20
bec aus e s pac es aren't allowed in U RL s . I ns ide this page, you'll
find s ome c ode and a bit of s truc tured XM L that looks like this :
...
<locations>
<location infoStyle="/maps?file=li&hl=en" id="A">
<point lat="44.564722" lng="-123.260833"/>
<icon class="noicon"/>
<info>
<address>
<line>Corvallis, OR</line>
</address>
<description></description>
</info>
</location>
</locations>
...
The Code
T he following P erl s c ript does the heavy lifting for the hac k by
finding the loc ations as s oc iated with your Flic kr c ontac ts ,
looking up the c oordinates for thos e loc ations at G oogle, and
writing the nec es s ary J avaSc ript to dis play the points on a map.
T he s c ript als o as s embles the H T M L nec es s ary to dis play your
c ontac ts ' buddy ic ons in the map its elf.
#!/usr/bin/perl
# gmap-contacts.pl
# This script creates a JavaScript file that plots points
# on a Google Map for a given Flickr member's contacts.
#
# You can get a Flickr API key, find your NSID, and read the
# full documentation for the Flickr API at:
#
# http://www.flickr.com/services/api/
#
# You can get a Google Maps API key and read the full
# documentation for the Google Maps API at:
#
# http://www.google.com/apis/maps/
use strict;
use Flickr::API;
use Flickr::API::Response;
use LWP::Simple;
use XML::Parser::Lite::Tree::XPath;
use URI::Escape;
my @users;
my @locations;
# Start the JavaScript file, and set the initial center point
# for the Google Map
print <<JSHEADER;
function addMapPoints( ) {
map.addControl(new GSmallMapControl( ));
map.centerAndZoom(new GPoint(-96.66, 40.817 ), 13);
JSHEADER
# Get a list of contacts
my $response = $api->execute_method('flickr.contacts.getPublicList
'user_id' => $nsid,
});
O nc e the s c ript is ready to go, run it from the c ommand line and
s pec ify a des c riptive name for the J avaSc ript file, s uc h as
addMapPoints .j s , like this :
T he s c ript will build the J avaSc ript file and note any loc ations it
c ouldn't trans late into c oordinates . N ext, you'll need to put
together the s tandard H T M L file that will hold the map. C reate a
text file c alled contacts -map.html and add the following H T M L ,
making s ure to inc lude your G oogle M aps A P I key and the
J avaSc ript file you jus t c reated in the header:
N ote in the <body> tag that the page will run the addMapPoints()
func tion onc e the page has loaded. T his func tiongenerated by
gmaps -contacts .pl and s tored in addMapPoints .j s initializes the
G oogle M ap and adds all of the points and c ontac t information.
A nd, of c ours e, you c an zoom or c lic k and drag the map, jus t as
you c an with any G oogle M ap. You c an even drag the map to
other c ountries and s ee if you have c ontac ts there. M os t
importantly, you'll s ee how your Flic kr c ontac ts are dis pers ed,
whic h might help you realize that Flic kr really is a way to s hare
photos with people throughout the world.
Hack 28. Find Flickrites in Your Mac
Address Book
You c ould c opy and pas te eac h of your c ontac ts ' email
addres s es into the P eople Searc h page at Flic kr
(http://www.flic kr.c om/find.gne), but s ome quic k s c ripting c an
s ave you time. M ac O S X is a highly s c riptable environment, and
this hac k s hows how you c an us e A ppleSc ript and the underlying
U nix tool c alled curl to find people in your A ddres s Book that
als o have Flic kr photos treams .
The Code
The script loops through people in your Address Book, checking Fli
to see if they're members. If a photostream is found, you
have the option to view it in your default browser. You can get a
Flickr API key at http://www.flickr.com/services/api/.
by Paul Bausch
*)
-- build the URL that will search for the Wish List
set beginID to 1
set endID to (offset of "\"" in thisNSID) - 1
set thisNSID to get text beginID thru endID of this
T he top of the s c ript s ets s ome variables for curl that will be
us ed later.
With the variables s et, the s c ript loops through all of the entries
in the A ddres s Book, looking for email addres s es . E ac h
individual email addres s found is us ed to build a Flic kr A P I
reques t U RL with the flickr.people.findByEmail method. O nc e
the U RL is s et, the do shell script c ommand us es curl to fetc h
the res pons e, and the contains c ommand looks for a Flic kr N SI D
as s oc iated with the email addres s .
You c an run the s c ript by c lic king the Run button in the Sc ript
E ditor. A s you find people in your A ddres s Book who are als o on
Flic kr, you'll have the option to view their photos treams , as
s hown in Figure 4 - 1 2 .
Figure 4-12. AppleScript prompt to view a
contact's photostream
To keep this s c ript one c lic k away from your A ddres s Book,
move the s c ript to the /Library/Scripts /Addres s Book Scripts
folder. T his way, you c an ac c es s the s c ript from your A ddres s
Book's Sc ripts menu. Run the s c ript at any time by s elec ting
Sc ript M enu Find Flic kerites from the A ddres s Book
applic ation's menu bar.
Finding fellow Flic kr us ers via your A ddres s Book may help you
learn more about s ome people you know c as ually and build your
own lis t of c ontac ts at Flic kr.
Hack 29. Surf Your Contacts
I f you don't already regularly vis it your Flic kr c ontac ts ' external
s ites , you might learn s omething more about your ac quaintanc es
and the photographers you admire by taking a look. I f you have
jus t a handful of c ontac ts , you c ould vis it eac h of your c ontac ts '
profile pages one by one and make a lis t of U RL s you'd like to
vis it; but if you have more than a dozen c ontac ts , a bit of P H P
s c ripting c an help you put together a mas ter s urfing lis t in a few
minutes .
<?php
// flickr_surf.php
// Finds web sites of Flickr contacts for given
// Flickr NSIDs. Use it to gather your Flickr
// contacts' web sites onto one page for easy
// surfing.
//
// You can get an API key and read the full documentation
// for the Flickr API at http://www.flickr.com/services/api/
You'll notic e that the s c ript c ontac ts the Flic kr A P I to find your
lis t of c ontac ts , and then c ontac ts the A P I again for eac h
c ontac t to find the us er's real name and profile U RL . Flic kr
does n't make s ite information available via the A P I , s o the
s c ript relies on s creen-s craping the profile pages to find that
data. Sc reen- s c raping involves downloading the H T M L of the
page and pic king through it with regular expres s ions to c herry-
pic k the required information. I t's a notorious ly brittle proc es s ,
and if Flic kr c hanges the H T M L of the profile page, the s c ript
won't be able to find the information you want. Be aware that you
may need to tweak the regular expres s ion s et as $regex to find
the web s ite name and U RL .
N ote als o that the s c ript is fairly reques t- intens ive. For every
pers on in your c ontac t lis t, this s c ript will make two reques ts of
the Flic kr s ervers . To give the Flic kr s ervers a bit of a break, the
s c ript then res ts for three s ec onds by c alling sleep(3). T his will
give the Flic kr s ervers a s mall res t between eac h c ontac t, but it
als o means you'll need to be patient while the s c ript is c ompiling
your lis t.
To run the c ode, upload the s c ript to your web s erver and brows e
to the page. T he U RL s hould look s omething like this :
http://www.example.com/flickr_surf.php
H ac ks 3 0 - 3 6
H ac k 3 3 . D ownload a L is t of P hotos
H ac k 3 4 . C ac he P hotos L oc ally
T his c hapter will s how you s ome tips and tric ks for managing a
large c ollec tion of photos on Flic kr, inc luding editing s everal
photos at onc e [Hack #35] and downloading a c omplete lis t of
your photos [Hack #33] . I f you have a large c ollec tion of photos
on Flic kr, you'll find out how to bac k up your photos [Hack #30]
and c omments [Hack #31] to your loc al c omputer for
s afekeeping. A nd if you've s tarted a Flic kr group, you'll find out
how to extend the management features by c reating a
maintenanc e bot [Hack #36] to help you keep the group running
s moothly.
Hack 30. Back Up Your Photos
You c ould write your own Flic kr A P I s c ript to grab all of your
photos , but luc kily, A ndrew Serff has s aved you the trouble by
writing a free J ava program c alled Flic krBac kup
(http://www.s unkenc ity.org/flic krbac kup/). T he program runs on
both M ac s and P C s , and it provides a vis ual interfac e for
bac king up your Flic kr photos . You c an download a c opy of
Flic krBac kup from its Sourc eForge projec t page at
http://www.s ourc eforge.net/projec ts /flic krbac kup.
T his c ommand will s tart the program, and you'll be greeted with
the authentic ation reques t s hown in Figure 5 - 1 .
Flic krBac kup will download thumbnails of all of your photos , and
you'll s ee a grid of your photos like the one s hown in Figure 5 - 2 .
Figure 5-2. Flickr Backup photo selection
window
From here, you c an s elec t whic h photos to bac k up. A t the time
of this writing there's no way to s elec t all photos at onc e, s o
you'll need to c lic k eac h photo individually. A lternately, you c an
c hoos e to bac k up c omplete photo s ets at Flic kr by c lic king the
Sets tab.
O nc e you've made your s elec tion, c lic k Bac kup Selec ted, and
you'll s ee the Flic kr Bac kup Wizard window. C lic k the Brows e
button and c hoos e a loc al folder to s tore images in, and Start
Bac kup will begin the proc es s . A s tatus bar will let you know how
the program is doing.
Flickr photo comments are usually light chit-chat, but you might
want to save them f or posterity.
The Code
You'll need s everal P erl modules ins talled on your s ys tem for
this s c ript to work. Flickr::API
(http://s earc h.c pan.org/~iamc al/Flic kr- A P I -
0 .0 7 /lib/Flic kr/A P I .pm) is us ed to find a lis t of photos for a given
us er, and XML::Simple (http://s earc h.c pan.org/~grantm/XM L-
Simple- 2 .1 4 /lib/XM L /Simple.pm) pars es through the A P I
res pons e. LWP::Simple (http://s earc h.c pan.org/~gaas /libwww-
perl- 5 .8 0 3 /lib/LWP /Simple.pm) grabs the H T M L at Flic kr to
s c rape c omments for a s pec ific photo.
#!/usr/bin/perl
# comments-backup.pl
# Creates a text file for each photo with comments
# at Flickr, and saves the comments to the file
#
# You can get an API key, find your NSID, and read the
# full documentation for the Flickr API at:
#
# http://www.flickr.com/services/api/
use strict;
use Flickr::API;
use Flickr::API::Response;
use LWP::Simple;
use XML::Simple;
my $page = get($link);
if ($page =~ m!<h3>Comments</h3>!mgis) {
print "Backing up comments for photo $id: $title\n";
my $section;
my $file = "$dir$id.txt";
open FILE, ">$file" or warn "Can't open $file\n";
print FILE "$title\n$datetaken\n$link\n\n";
($section) = $page =~ m!<h3>Comments</h3>(.*?)</table>!s;
while ($section =~ m!<tr valign="top">.*?<h4>(.*?)</h4>.*?<p
my $commenter = $1;
my $comment = $2;
$comment =~ s!<.+?>!!gs;
($commenter) = $commenter =~ m!<a href.*?>(.*?)</a>!gis;
print FILE "$commenter: $comment\n";
}
print FILE "\n\n";
close FILE;
}
}
O nc e the s c ript has a lis t of photos , it downloads eac h photo's
detail page from Flic kr and extrac ts any c omments with regular
expres s ions . For eac h photo that has c omments , the s c ript
c reates a text file with the photo I D and adds to it the title, date,
U RL , and, of c ours e, c omments .
To s tart your bac kup, run the s c ript from a c ommand prompt like
this :
perl comments-backup.pl
Bac king up c omments is n't a nec es s ity, but if you want to know
that your c omments are going to be available for years to
c omeand give yours elf the ability to s earc h through themyou
might want to try it.
Hack 32. Make a Contact Sheet
Photo-management s oftware
QOOP
I mageMagick
convert
montage
O ffers various options for c ompos iting multiple images
together into a s ingle large image. I t makes a great all-
purpos e c ontac t s heet generator.
I mageMagick
$ getPhotoList.pl bunnies
T his c ommand downloads all the images in the
bunnies .ph file and puts them into a s imilarly named
direc tory:
$ getSnaps.pl bunnies
G et to the c ommand line and c hange direc tory (cd) to where your
images res ide. T hen invoke the montage c ommand, as follows :
T his produc es a montage with only three tiles per row, ins tead of
the default five:
Try it and s ee. O f c ours e, for a tool to be truly us eful, it als o has
to have the potential to be truly annoying.
See Also
[Hack #34]
[Hack #43]
[Hack #49]
Hack 33. Download a List of Photos
I f you poke around Flic kr for more than a few minutes , one thing
bec omes evident: there are a lot of photos on the s ite. When I
firs t joined the Squared C irc le group, there were nearly 3 ,0 0 0
photographs of c irc ular objec ts in the group pool. A t the time of
this writing, the number is over 2 0 ,0 0 0 . T he Flowers group has
over 5 0 ,0 0 0 photos . Some prolific photographers , s uc h as
Fubuki, have uploaded over 1 0 ,0 0 0 of their own photos . A nd
then there are the tags . A t this moment, there are approximately
2 ,3 0 0 photos that c ontain the tag pie; 2 1 ,0 0 0 photos that
c ontain the tag apple; and 1 1 1 ,0 0 0 photos that c ontain the tag
s uns et.
Flic kr provides various means to help you find the good s tuff,
s uc h as the "interes tingnes s " feature, but as a hac ker, it's fun to
us e s ilic on to c runc h the photos up and s pit them out in various
ways . We'll s tart with a s et of P erl s c ripts for downloading lis ts of
photos . T hes e are bas ic workhors e s c ripts that I us e all the
time, in c onjunc tion with other s c ripts that operate on thes e lis ts
of photos .
I t might be tempting to try to build a big monolithic applic ation
that does everything you might pos s ibly want to do with Flic kr,
but I 've found it s impler and more flexible to work with a s et of
s mall modular c ommand- line s c ripts that are des igned to work
together. T his is the s ame philos ophy us ed to build many of the
c ommand- line utilities in U nix. I f you're c omfortable with the
c ommand line, you'll like this approac h.
flickr.photos.search
flickr.people.getPublicPhotos
flickr.groups.pools.getPhotos
<rsp stat="ok">
<photos page="1" pages="1" perpage="100" total="7">
<photo id="41865069" owner="26084283@N00" secret="ccb3eed603" serv
<photo id="40147327" owner="28226466@N00" secret="2388324058" serv
<photo id="35777919" owner="43091440@N00" secret="78cd0de7c7" serv
<photo id="33824150" owner="10202855@N00" secret="6368d0a654" serv
<photo id="33824088" owner="10202855@N00" secret="1aeed42f5f" serv
<photo id="24152735" owner="35294562@N00" secret="b3766cfdd7" serv
<photo id="1465720" owner="44146188@N00" secret="2d5487bbe5" serve
</photos>
</rsp>
photo_id
secret
server
owner
title
T he photo's title.
ispublic
XML::Simple
I f you're mis s ing any of thes e modules , you c an ins tall eac h of
them from C P A N , like this :
ppm install
package name
The Code
#!/usr/bin/perl -s
#
# getPhotoList.pl - Jim Bumgardner
#
use Flickr::API;
use XML::Simple;
use Data::Dumper;
$Data::Dumper::Terse = 1; # avoids $VAR1 = * ; in dumper output
$Data::Dumper::Indent = $verbose? 1 : 0; # more concise output
$syntax = <<EOT;
Options:
-all Photos must match all tags (tag search only)
-recent=X Only provide photos posted within the last X days (ta
-limit=X Provide no more than X photos
-license=X Provide photos with license X
EOT
$nbrPages = 0;
$photoIdx = 0;
$user_id = '';
$min_taken_date = '';
$max_taken_date = '';
if ($recent)
{
die "-recent option only valid for tag search\n" if $method ne '
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
gmtime(time - $recent*24*60*60);
$min_taken_date = sprintf "%04d-%02d-%02d 00:00:00",1900+$year,$
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
gmtime(time);
$max_taken_date = sprintf "%04d-%02d-%02d 00:00:00",1900+$year,$
}
if ($username)
{
# look up user ID if a username was provided
#
my $response = $api->execute_method('flickr.people.findByUsernam
username => $username} );
die "Problem determining user_id: $response->{error_message}\n"
my $xm = $xmlp->XMLin($response->{_content});
$user_id = $xm->{user}->{id};
print "Userid: $user_id\n";
}
do
{
my $params = { per_page => 500,
page => $nbrPages+1};
$params->{tags} = $tags if $tags;
$params->{user_id} = $user_id if $user_id;
$params->{group_id} = $group_id if $group_id;
$params->{min_taken_date} = $min_taken_date if $min_taken_date;
$params->{max_taken_date} = $max_taken_date if $max_taken_date;
$params->{license} = $license if $license;
$params->{extras} = $extras if $extras;
$params->{tag_mode} = 'all' if $all;
my $xm = $xmlp->XMLin($response->{_content},forcearray=>['photo'
$photos = $xm->{photos};
print "Page $photos->{page} of $photos->{pages}\n";
$api_key = '12345';
$sharedsecret = '6789';
Replac e 12345 with your ac tual A P I key, and replac e 6789 with
your ac tual s hared s ec ret. (See C hapter 6 for more information
on A P I keys and s hared s ec rets .)
getPhotoList.pl aardvark
@photos = (
{ 'owner' => '24512271@N00', 'isfriend' => '0', 'ispublic' => '1',
'title' => 'Groupportrait', 'server' => '3', 'id' => '5024662', 'i
{ 'owner' => '66208233@N00', 'isfriend' => '0', 'ispublic' => '1',
'title' => 'Grooming is important', 'server' => '8', 'id' => '1199
{ 'owner' => '44124388719@N01', 'isfriend' => '1', 'ispublic' => '
'title' => 'The Night Visitor', 'server' => '4', 'id' => '5043567'
{ 'owner' => '66208233@N00', 'isfriend' => '0', 'ispublic' => '1',
'title' => 'Buffy_close', 'server' => '7', 'id' => '6883675', 'isf
...
I f you want to require that eac h photo matc h all the tags , us e the
optional -all argument.
getPhotoList.pl -u fubuki
getPhotoList.pl -g
group_id
getPhotoList.pl -u fubuki
getSnaps.pl fubuki
O ther hac ks in this book demons trate how to us e thes e lis ts for
projec ts that involve large- s c ale image manipulation, s uc h as
photo mos aic s [Hack #49] or c olor pic kers [Hack #45] .
$photoList = shift;
require "$photoList";
M y own s c ripts us ually automatic ally add the .ph extens ion if it
has n't already been provided:
$photoList = shift;
$photolist .= '.ph' if !($photolist =~ m/\./);
require "$photoList";
H ere's a bas ic loop that walks through the images and c onverts
them into U RL s to thumbnails :
#!/usr/bin/perl
use LWP::Simple;
$photolist = shift;
$photolist .= '.ph' if !($photolist =~ m/\./);
$photo_id = shift;
die "getSnap.pl [photolist_file] [photo_id#]\n" if !$photo_id;
require "$photolist";
foreach $p (@photos)
{
if ($p->{id} eq $photo_id)
{
$photo = $p;
last;
}
}
[Hack #34]
[Hack #43]
[Hack #49]
Hack 34. Cache Photos Locally
D on't download photos that are larger than you need. For
mos t of my projec ts , I require only s mall thumbnail
images . T hes e download fas ter from Flic kr and put les s
of a s train on their s ervers .
photo_id
secret
server
I f the <size> qualifier is left out, as in the firs t variant, you'll get
a medium- s ized vers ion of the image, whic h is 5 0 0 pixels on the
longes t s ide. T his is the vers ion people s ee on the photo's detail
page.
No qualifier
photo_id 3263379
secret 21ee6ccacf
secret 3
I f you're mis s ing the LWP::Simple module, you c an ins tall it from
C P A N , like this :
T he P erl s c ripts in this hac k als o require that you have the
getPhotoLis t.pl s c ript from [Hack #33] .
The Code
C reate a file c alled getSnaps .pl and enter the following c ode into
it:
#!/usr/bin/perl -s
use LWP::Simple;
$photolist = shift;
$dirname = shift;
die "getSnaps.pl [-big] <photolist_file> [dirname]\n" if !$photoli
require "$photolist";
$nbrAdded = 0;
if (!(-e $dirname))
{
print "Making directory $dirname\n";
`mkdir $dirname`;
}
$hasSmall = 0;
getPhotoList.pl
tag
getSnaps.pl
tag
$ getPhotoList.pl aardvark
Searching for photos with tags=aardvark ...
Page 1 of 1
31 photos found matching tags aardvark written to aardvark.ph
$ getSnaps.pl aardvark
Making directory aardvark
Adding aardvark/5024662_t.jpg...
Adding aardvark/11999049_t.jpg...
Adding aardvark/5043567_t.jpg...
(etc...)
Adding aardvark/23418439_t.jpg...
31 added
When the s ec ond s c ript is done running, you'll find a new folder
named aardvark, whic h c ontains all the thumbnails that are
referenc ed the photolis t file aardvark.ph that was c reated by the
firs t s c ript. I f you wis h to s tore the photos in a different
direc tory, s pec ify it on the c ommand line, like s o:
I f the direc tory does n't already exis t, the s c ript will c reate it.
$fnam = "$dirname/$photo->{id}$suffix.jpg";
T his c ons truc ts the (more c omplic ated) path to the file, and
makes the s ubdirec tories , if nec es s ary.
Before c reating the file, you s hould make the direc tories leading
up to the file, if nec es s ary, like s o:
[Hack #33]
[Hack #43]
[Hack #45]
[Hack #49]
Hack 35. Edit Photos as a Batch
O ften, when you're brows ing around Flic kr you'll notic e a way
that s omeone els e is us ing tags that you c ould apply to your own
photos . For example, you might have tagged s everal of your
photos taken in national parks with the words Yos emite or
Yellows tone, but not inc luded the tag national park.
You c ould brows e to eac h photo's detail page and add the tag
manually, or you c ould take advantage of Flic kr's batc h- editing
features to add the tag to all the relevant photos in one fell
s woop.
Some large groups deal with this problem by pos ting an upload
limit in the group des c ription, s uc h as "N o more than three
photos a day." H owever, many c ontributors either don't notic e
thes e rules , don't s peak the language they are pos ted in, or
s imply don't c are. M anually enforc ing upload limits c an be a
c hore; if there are tons of people s ubmitting photos , it's diffic ult
to keep trac k of who has s ubmitted what. A nd unfortunately,
Flic kr has no mec hanis m for limiting uploads to group pools .
To run this s c ript, you'll need an API key, a s hared s ecret, and an
authorization token, as explained in [Hack #40] . T hes e
parameters will be us ed to tell the A P I that you have s uffic ient
permis s ions to delete photos from the group pool.
I f you're mis s ing this module, you c an ins tall it from C P A N , like
this :
Firs t, c reate a file for s toring the authentic ation information. C all
it bot_auth.ph, and s tore the following c ode in it:
$api_key = '928c994908f02385d1d97a457003cb71';
$shared_secret = '8698bb062a08ca11';
$auth_token = '127122-92395db066e82035';
1;
N ext, c reate the file for the main bot s c ript, cleanPool.pl. I 'll
des c ribe this c ode in s ec tions , s tarting with s ome bas ic s etup to
s pec ify whic h modules we are going to us e and require the
bot_auth.ph file:
#!/usr/bin/perl -s
use Flickr::API;
use XML::Simple;
N ext is a data s truc ture, whic h des c ribes the rules for eac h
group we are adminis trating:
@groups = (
{name=>'Flowers', id=>'13378274@N00', limit=>3,
submitWindow=>7*60*60, cutoffTime => time - 1*24*60*60},
{name=>'JPG Mag', id=>'52240402017@N01', limit=>1,
submitWindow=>7*60*60, cutoffTime => time - 1*24*60*60},
{name=>'Least Interesting', id=>'55489371@N00', limit=>1, keepN
submitWindow=>0, cutoffTime => 0},
{name=>'Your Favorites', id=>'74565724@N00', limit=>2, keepNewe
submitWindow=>0, cutoffTime => 0},
{name=>'Body Language', id=>'82402134@N00', limit=>3,
submitWindow=>12*60*60, cutoffTime => time - 1*24*60*60},
{name=>'Hand Signals', id=>'80263920@N00', limit=>3,
submitWindow=>12*60*60, cutoffTime => time - 1*24*60*60},
{name=>'Critique - Advanced',id=>'48467233@N00', limit=>0,
submitWindow=>0, cutoffTime=>0},
{name=>'Critique - For Starters',id=>'16162753@N00', limit=>0,
submitWindow=>0, cutoffTime=>0},
{name=>'Critique - Intermediate',id=>'71433669@N00', limit=>0,
submitWindow=>0, cutoffTime=>0}
);
my $response = $api->execute_method('flickr.groups.pools.getPh
group_id => $group->{id},
per_page => 500,
page => $nbrPages+1}
);
my $xml = $response->{_content};
$xml =~ s/ownername="[^"]+"//g; # Get rid of stuff that
$xml =~ s/title="[^"]+"//g; # may causing parsing problem
$xm = XMLin($xml);
$photolist = $xm->{"photos"}->{"photo"};
$maxTime = 0;
foreach $id (keys %{$photolist})
{
$photo = $photolist->{$id};
$photo->{id} = $id;
push @photos, $photo;
$maxTime = $photo->{dateadded} if $photo->{dateadded} > $max
$photoIdx++;
$nbrAdded++;
}
print "$photoIdx...\n";
++$nbrPages;
} while ($nbrAdded > 0 && $maxTime > $group->{cutoffTime});
N ext, the s c ript s orts the photos by time. Some groups have a
polic y that newer s ubmis s ions s hould c aus e older s ubmis s ions
to be deleted. I n this c as e, we s ort in revers e- c hronologic al
order. O therwis e, we s ort in c hronologic al order:
I t then walks through the $owners has h and identifies photos that
need to be rejec ted, bas ed on our rules . T he photo rec ords are
pus hed onto an array c alled @rejects:
# Reject photos
#
my $totRejected = 0;
my $totGroup = @photos;
foreach $photo (@rejects)
{
print "Rejecting $photo->{id}...\n";
my $res = $api->execute_method('flickr.groups.pools.remove', {
group_id => $group->{id},
photo_id => $photo->{id}
auth_token => $auth_toke
);
if (!$res->{success})
{
print "Error rejecting $photo->{id}: $res->{error_message}\n
}
else {
$totRejected++;
}
}
T his is the only c all that requires authentic ation, s o we pas s the
authentic ation token here. A s we rejec t photos , we c ount
s uc c es s ful rejec tions .
We then s how the res ults for this group and loop onto the next
one:
# Show results
#
print "$totRejected rejected of $totGroup for group $group->{nam
# end of loop
}
$ cleanPool.pl
Flowers...
500...
1000...
0 rejected of 1000 for group Flowers
JPG Mag...
499...
999...
0 rejected of 999 for group JPG Mag
Least Interesting...
500...
731...
0 rejected of 731 for group Least Interesting
Your Favorites...
500...
1000...
1500...
2000...
2500...
3000...
3101...
0 rejected of 3101 for group Your Favorites
Body Language...
500...
1000...
0 rejected of 1000 for group Body Language
Hand Signals...
277...
0 rejected of 277 for group Hand Signals
Critique - Advanced...
0...
0 rejected of 0 for group Critique - Advanced
Critique - For Starters...
0...
0 rejected of 0 for group Critique - For Starters
Critique - Intermediate...
0...
0 rejected of 0 for group Critique - Intermediate
I run this s c ript every 2 0 minutes , s o there's us ually little that
needs c leaning; indeed, in this run, nothing ac tually got deleted.
I s hould point out that tec hnic ally, this s c ript rejec ts photos that
exc eed s ome limit (s uc h as three pos tings ) in any 1 2 - hour
period. T his is not quite the s ame thing as "three per day," but it
is eas ier to detec t. Sinc e Flic kr us ers c ome from all over the
world, it's diffic ult to prec is ely define what "onc e a day" means ;
however, this method works pretty well.
[Hack #40]
Chapter 6. API Basics
H ac ks 3 7 - 4 2
T he A P I P age
A P I M ethods
I dentifying U s ers
I dentifying G roups
I dentifying P hotos
Talking to the A P I
T his is the loc ation of Flic kr's A P I doc umentation page (whic h
we'll refer to as "the A P I page" for s hort). T he A P I page
c ontains a lis t of eac h of the A P I methods , whic h are s ervic es
that Flic kr c an perform for you. E ac h method lis ted on the page
is linked to a des c ription of that partic ular method.
Authorization
flickr.auth.checkToken
flickr.auth.getFrob
flickr.auth.getFullToken
flickr.auth.getToken
Blogs
T hes e methods permit you to interac t with any blogs that you
have c onfigured to work with Flic kr:
flickr.blogs.getList
flickr.blogs.postPhoto
Contacts
Favorites
People
Photos
O f c ours e, photos are the bread, the butter, and the manna of
Flic kr, s o the majority of the A P I c alls are in the flickr.photos
group:
flickr.photos.addTags
flickr.photos.getAllContexts
flickr.photos.getContactsPhotos
flickr.photos.getContactsPublicPhotos
flickr.photos.getContext
flickr.photos.getCounts
flickr.photos.getExif
flickr.photos.getInfo
flickr.photos.getNotInSet
flickr.photos.getPerms
flickr.photos.getRecent
flickr.photos.getSizes
flickr.photos.getUntagged
flickr.photos.removeTag
flickr.photos.search
flickr.photos.setDates
flickr.photos.setMeta
flickr.photos.setPerms
flickr.photos.setTags
flickr.photos.transform.rotate
flickr.photos.upload.checkTickets
Licenses
Flic kr s upports the C reative C ommons lic ens ing s ys tem [Hack
#16], and thes e c alls permit you to manipulate and query
lic ens e information:
flickr.photos.licenses.getInfo
flickr.photos.licenses.setLicense
Notes
You may have already notic ed that on Flic kr, you c an plac e notes
[Hack #10] direc tly on top of your photos , or other people's
photos . T hes e methods allow you to manipulate thos e notes :
flickr.photos.notes.add
flickr.photos.notes.delete
flickr.photos.notes.edit
Photo Sets
flickr.photosets.addPhoto
flickr.photosets.create
flickr.photosets.delete
flickr.photosets.editMeta
flickr.photosets.editPhotos
flickr.photosets.getContext
flickr.photosets.getInfo
flickr.photosets.getList
flickr.photosets.getPhotos
flickr.photosets.orderSets
flickr.photosets.removePhoto
You c an als o get this s ame information (in more human- readable
form) by vis iting the A P I doc umentation page at
http://www.flic kr.c om/s ervic es /api/.
Tags
U s ers c an attac h tags [Hack #10] to photos on Flic kr, and thes e
A P I methods enable you to view thos e tags :
flickr.tags.getListPhoto
flickr.tags.getListUser
flickr.tags.getListUserPopular
flickr.tags.getRelated
T hes e methods are intended for hac kers like us to tes t the A P I :
flickr.test.echo
flickr.test.login
URLs
O n Flic kr, you c an find us ers , photos , and groups at predic table
and fixed U RL s . I t's s imple enough to c ons truc t thes e U RL s out
of their c ons tituent parts by c onjoining s trings , but you c an als o
us e the firs t three methods in this group:
flickr.urls.getGroup
flickr.urls.getUserPhotos
flickr.urls.getUserProfile
flickr.urls.lookupGroup
flickr.urls.lookupUser
C lic k the A P I Keys link (under "Read thes e firs t:"), and then
c lic k the "A pply for your key online now" link. A lternatively, jus t
go direc tly to the following U RL , whic h is where you'll end up:
Fill out the form, and pres s the A pply button. You'll be pres ented
with an A P I key, as s hown in Figure 6 - 1 . You c an rec ord this
information in a text file, or jus t return to the Flic kr A P I page
when you need to s ee it.
A n eas y way to dis c over your own user_id without us ing the A P I
is to view the image properties of your Flic kr ic on and examine
the U RL of the image. M y ic on's U RL reads as follows (my
user_id is s hown in bold):
http://photos2.flickr.com/buddyicons/94832693@N00.jpg?1119657139
I t's eas ier for other people to gues s your Flic kr web addres s if
you make your alias the s ame as your us ername. I probably
s hould have c hos en j bum for my alias , but now it's too late. O h
well!
A gain, it's eas ies t for us ers if the poolname c orres ponds to the
group name, but in ac tuality this does n't happen that often,
s inc e there are often multiple groups that deal with the s ame
kinds of s ubjec ts . I f you want to c reate a group for c ollec ting
pic tures of mus hrooms , c hanc es are you're not the firs t!
M us hrooms , Fungi, and Fungus are already taken. A t the
moment, M yc ology is s till free. G rab it while you c an!
Identifying Photos
J us t about every A P I method that returns information about
photos returns the following three piec es of information:
photo_id
secret
server
While the photo_id is often dis played public ly in the brows er's
addres s bar (as part of the U RL for the photo's detail page), the
secret and server are normally not vis ible to end us ers , making it
s lightly harder for c as ual brows ers to s wipe photos from Flic kr.
Fortunately for us , there's an eas y way to retrieve this info
without even us ing the A P I .
http://static.flickr.com/server/id_secret.jpg
T his tells us that the photo's secret is 16804205 and its server is
13.
Deconstructing Flickr URLs
You may have notic ed in the previous s ec tion that Flic kr us es
c ons is tent naming c onventions for its U RL s . T his makes it eas y
to c ons truc t thes e U RL s , given c ruc ial bits of information s uc h
as user_ids and photo_ids . H ere are s ome examples :
http://www.flickr.com/photos/<user_id>
http://www.flickr.com/photos/<alias>
U RL s for profiles :
http://www.flickr.com/people/<user_id>
http://www.flickr.com/people/<alias>
U RL s for groups :
http://www.flickr.com/groups/<group_id>/
http://www.flickr.com/gouprs/<poolname>/
http://www.flickr.com/photos/<user_id>/<photo_id>/
http://www.flickr.com/photos/<alias>/<photo_id>/
http://flickr.com/photo.gne?id=<photo_id>
http://static.flickr.com/<server>/<photo_id>_<secret>.jpg
http://static.flickr.com/<server>/<photo_id>_<secret>_<size>.jpg
REST
XML-RPC
SOAP
T here are two s imple ways to talk to the A P I us ing your web
brows er: you c an type RE ST U RL s direc tly into your brows er's
addres s bar (the hard way), or you c an us e Flic kr's A P I E xplorer
(the eas y way).
H ere's an example. Try pas ting this into your web brows er's
addres s bar:
http://www.flickr.com/services/rest/?method=flickr.test.echo&api_k
Subs titute your own A P I key for your_api_key, and s ubs titute the
name of any Flic kr A P I method for flickr.test.echo. You c an als o
add any parameters that are required by the c all, jus t as the
above example us es param1 and param2 with flickr.test.echo.
<rsp stat="ok">
<method>flickr.test.echo</method>
<api_key>81a8f5d6c402d26f425e4361d07f85ba</api_key>
<foo>bar</foo>
</rsp>
From there, you c an find the A P I E xplorer for eac h method pretty
quic kly.
C lic king the A P I E xplorer link at the bottom of this page will
take you to the A P I E xplorer form s hown in Figure 6 - 2 , whic h
res ides at http://www.flic kr.c om/s ervic es /api/explore/?
method=flic kr.photos .getI nfo.
C opying and pas ting the I D of the photo labeled "A ll the c at toys
on A mazon" (60147370) and then pres s ing the C all M ethod...
button produc es the following XM L :
<rsp stat="ok">
<photo id="60147370" secret="0bdfee3691" server="30" dateuploaded=
<owner nsid="94832693@N00" username="jbum" realname="Jim Bumgardne
<title>All the cat toys on Amazon</title>
<description>
All the cat toys on Amazon.
<a href="http://www.coverpop.com/pop/cattoys/">http://www.coverpop
</description>
<visibility ispublic="1" isfriend="0" isfamily="0"/>
<dates posted="1131226468" taken="2005-11-05 13:34:28" takengranul
<permissions permcomment="3" permaddmeta="2"/>
<editability cancomment="1" canaddmeta="1"/>
<comments>1</comments>
<notes>
</notes>
<tags>
<tag id="197715539" author="94832693@N00" raw="cats">cats</tag>
<tag id="197715540" author="94832693@N00" raw="cat toys">cattoys</
<tag id="197715541" author="94832693@N00" raw="amazon">amazon</tag
<tag id="197715542" author="94832693@N00" raw="mosaic">mosaic</tag
<tag id="197715543" author="94832693@N00" raw="coverpop">coverpop<
</tags>
<urls>
<url type="photopage">http://www.flickr.com/photos/krazydad/601473
</urls>
</photo>
</rsp>
I t's als o ins truc tive to enter invalid information and s ee what
kind of res ult you get. For example, entering aaaa for the photo_id
(whic h is not a valid photo_id) returns the following res ult:
<rsp stat="fail">
<err code="1" msg="Photo not found"/>
</rsp>
See Also
[Hack #38]
[Hack #39]
Hack 38. Talk to the API with Perl
T his hac k pres ents a few different P erl s c ripts that talk to the
Flic kr A P I . Firs t, s ome s imple examples s how the bas ic method;
the two different tec hniques that follow it ac c omplis h a more
us eful tas k. T he programs in [Hack #39] mirror the programs in
this hac k.
Getting a User's ID
#!/usr/bin/perl -s
use LWP::Simple;
$username = shift;
die ("Please specify a Flickr username\n") if !$username;
$url = "http://www.flickr.com/services/rest/?method=$method&api_ke
$xml = get $url;
print $xml;
$api_key = 'e072dadf32c2a6da1b7b7592e88ebe9e';
You c an apply for an A P I key at
http://www.flic kr.c om/s ervic es /api/key.gne.
#!/usr/bin/perl -s
use LWP::Simple;
use XML::Simple;
use Data::Dumper;
$username = shift;
die ("Please specify a Flickr username\n") if !$username;
$method = 'flickr.people.findByUsername';
$url = "http://www.flickr.com/services/rest/?method=$method&api_ke
$xml = get $url;
$xm = XMLin($xml);
if ($xm->{err})
{
print "Error getting user id: ",$xm->{err}->{msg},"\n";
exit;
}
$user_id = $xm->{user}->{id};
print "User ID: $user_id\n";
T his program takes an optional option, -debug, whic h c an be us ed
to dump the c ontents of the data s truc ture produc ed by XMLin(),
the pars ing func tion provided by XML::Simple. T he program dumps
it us ing the Dumper() func tion provided by Data::Dumper, an
inc redibly helpful way to figure out what kind of data s truc tures
you are being c onfronted with. H ere's a s ample run with
debugging turned on:
You might have notic ed that the nsid and id fields in the returned
data s truc tures are the s ame. A t the moment, Flic kr I D s and
N SI D s are identic al, and we'll tend to us e them interc hangeably
in this book. I t is pos s ible, though, that at s ome time in the
future the two I D s ys tems will diverge.
C reate a new file c alled getUs ers Lates t.pl and add the following
P erl c ode:
#!/usr/bin/perl -s
use LWP::Simple;
use XML::Simple;
use Data::Dumper;
$Data::Dumper::Terse = 1; # avoids $VAR1 = * ; in dumper output
$username = shift;
die ("Please specify a Flickr username\n") if !$username;
#
# Get user's ID
#
$method = 'flickr.people.findByUsername';
$url = "http://www.flickr.com/services/rest/?method=$method" .
"&api_key=${api_key}&username=${username}";
$xml = get $url;
$xm = XMLin($xml);
if ($xm->{err})
{
print "Error getting user id: ",$xm->{err}->{msg},"\n";
exit;
}
$user_id = $xm->{user}->{id};
#
# Get user's most recent photos
#
$method = 'flickr.people.getPublicPhotos';
$url = "http://www.flickr.com/services/rest/?method=$method" .
"&api_key=$api_key&user_id=$user_id&per_page=1";
$xml = get $url;
$xm = XMLin($xml);
print Dumper($xm),"\n" if $debug;
if ($xm->{err})
{
print "Error getting most recent photo: ",$xm->{err}->{msg},"\
exit;
}
$photo_id = $xm->{photos}->{photo}->{id};
$photo_secret = $xm->{photos}->{photo}->{secret};
$photo_server = $xm->{photos}->{photo}->{server};
#
# Formulate URL to the photo (image)
#
$imgUrl = sprintf "http://static.flickr.com/%d/%d_%s.jpg",
$photo_server,$photo_id, $photo_secret;
#
# Formulate URL to the photo's Flickr page
#
$pageUrl = sprintf "http://www.flickr.com/photos/%s/%d/",
$user_id, $photo_id;
#
# Get photo info
#
$method = 'flickr.photos.getInfo';
$url = "http://www.flickr.com/services/rest/?method=$method" .
"&api_key=$api_key&photo_id=$photo_id";
$xml = get $url;
$xm = XMLin($xml);
print Dumper($xm),"\n" if $debug;
if ($xm->{err})
{
print "Error getting most recent photo: ",$xm->{err}->{msg},"\
exit;
}
#
# Get title
#
$title = $xm->{photo}->{title};
#
# Get date uploaded
#
$dateuploaded = $xm->{photo}->{dateuploaded};
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(
$datestr = sprintf '%4d-%02d-%02d %2d:%02d', $year+1900,$mon+1,$md
#
# Join tags into a single string
#
$tags = $xm->{photo}->{tags}->{tag};
$taglist = join ', ',map {$tags->{$_}->{content}} keys %{$tags};
#
# Output HTML page containing URL to photo, image, and tags.
#
print <<EOT;
<html>
<head>
<title>Sample Photo Page</title>
</head>
<body>
<center>
The latest from $username...<br>
<a href="$pageUrl"><img src="$imgUrl" /></a><br>
Title: $title<br>
Uploaded: $datestr<br>
$taglist
</center>
</body>
</html>
EOT
Some of the data s truc tures involved here are bit c omplic ated,
and it is not eas y to predic t how to generate the c omplex
referenc es needed to extrac t c ertain fields , as in this line:
$photo_id = $xm->{photos}->{photo}->{id};
T his next program is a port of the previous one with exac tly the
s ame features . T he only differenc e is that it us es Flickr::API
ins tead of LWP::Simple. Flickr::API is intended to provide a layer
of glue, freeing you from the nitty- gritty details of dealing with
the A P I . I n this c as e, however, you'll notic e that both programs
are nearly the s ame length!
C reate a new file c alled getUs ers Lates t2.pl and add the following
P erl c ode:
#!/usr/bin/perl -s
#
# Initialize Flickr API
#
my $api = new Flickr::API({'key' => $api_key});
#
# Get user's ID
#
my $response = $api->execute_method('flickr.people.findByUsername'
username => $username}
);
if (!$response->{success})
{
print "Error getting user id: ",$response->{error_message},"\n
exit;
}
$xm = XMLin($response->{_content});
print Dumper($xm),"\n" if $debug;
$user_id = $xm->{user}->{id};
#
# Get user's most recent photos
#
my $response = $api->execute_method('flickr.people.getPublicPhotos
user_id => $user_id,
per_page => 1}
);
if (!$response->{success})
{
print "Error getting most recent photo: ",$response->{error_me
exit;
}
$xm = XMLin($response->{_content});
print Dumper($xm),"\n" if $debug;
$photo_id = $xm->{photos}->{photo}->{id};
$photo_secret = $xm->{photos}->{photo}->{secret};
$photo_server = $xm->{photos}->{photo}->{server};
#
# Formulate URL to the photo (image)
#
$imgUrl = sprintf "http://static.flickr.com/%d/%d_%s.jpg",
$photo_server,$photo_id, $phot
#
# Formulate URL to the photo's Flickr page
#
$pageUrl = sprintf "http://www.flickr.com/photos/%s/%d/",
$user_id, $photo_id;
#
# Get photo info
#
my $response = $api->execute_method('flickr.photos.getInfo', {
photo_id => $photo_id}
);
if (!$response->{success})
{
print "Error getting photo info: ",$response->{error_message},
exit;
}
$xm = XMLin($response->{_content});
print Dumper($xm),"\n" if $debug;
#
# Get title
#
$title = $xm->{photo}->{title};
#
# Get date uploaded
#
$dateuploaded = $xm->{photo}->{dateuploaded};
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(
$datestr = sprintf '%4d-%02d-%02d %2d:%02d', $year+1900,$mon+1,$md
#
# Join tags into a single string
#
$tags = $xm->{photo}->{tags}->{tag};
$taglist = join ', ',map {$tags->{$_}->{content}} keys %{$tags};
#
# Output HTML page containing URL to photo, image, and tags.
#
print <<EOT;
<html>
<head>
<title>Sample Photo Page</title>
</head>
<body>
<center>
The latest from $username...<br>
<a href="$pageUrl"><img src="$imgUrl" /></a><br>
Title: $title<br>
Uploaded: $datestr<br>
$taglist
</center>
</body>
</html>
EOT
I f you look c los ely, you'll s ee that the two programs are nearly
identic al and that in this c as e, Flickr::API is n't really buying you
very muc h. A n additional line has been added near the top to
initialize Flickr::API:
my $api = new Flickr::API({'key' => $api_key});
$xm = XMLin($response->{_content});
$photo_id = $xm->{photos}->{photo}->{id};
you c ould omit the XMLin() s tep and s ay this , in jus t one line:
$photo_id = $response->{tree}->{children}->[1]->{children}->[1]->{
H owever, you'll notic e that the data s truc ture that mus t be
travers ed to find the photo I D (a data s truc ture produc ed by
XML::Parser::Lite::Tree, the XM L pars er us ed internally by
Flickr::API) is more intric ate (and, to my eye, les s intuitive
bec aus e of all thos e generic - looking children) than the s truc ture
returned by XML::Simple. T his intric ac y generally leads to more
c oding mis takes , s o I prefer to us e XML::Simple.
[Hack #37]
[Hack #39]
[Hack #40]
Hack 39. Talk to the API with PHP
Getting a User's ID
C reate a new text file c alled tes tapi.php and enter the following
c ode:
<?
$username = 'jbum';
if (isset($_GET['username']))
$username = $_GET['username'];
#
# Get user's ID
#
$method = 'flickr.people.findByUsername';
$url = "http://www.flickr.com/services/rest/?method=$method&api_ke
$response = file_get_contents($url);
echo htmlspecialchars($response);
?>
$api_key = 'e072dadf32c2a6da1b7b7592e88ebe9e';
You c an apply for an A P I key at
http://www.flic kr.c om/s ervic es /api/key.gne.
To tes t the program (and all the programs in this hac k), upload it
to your web s erver and then type the addres s of the program into
your brows er's addres s bar:
http://www.yourdomain.com/testapi.php
http://www.yourdomain.com/ testapi.php?username=special
Sinc e the A P I kits available for P H P inc lude XM L pars ing, this is
a good time to s tart us ing them. We'll s tart with the firs t A P I kit
that was made for P H P.
<?
require_once 'Flickr/API.php';
$username = 'jbum';
if (isset($_GET['username']))
$username = $_GET['username'];
#
# Get user's ID
#
$response = $api->callMethod('flickr.people.findByUsername',
array(
if (!$response)
{
echo "Error getting user id: ".$api->getErrorMessage( )."\n";
exit;
}
$user = $response->getElement(array(0));
$user_id = $user->getAttribute('id');
?>
C reate a new file c alled getUs ers Lates t.php and add the following
c ode:
<?
require_once 'Flickr/API.php';
$username = 'jbum';
if (isset($_GET['username']))
$username = $_GET['username'];
#
# Get user's ID
#
$response = $api->callMethod('flickr.people.findByUsername',
array( 'username' => $username ));
if (!$response)
{
echo "Error getting user id: ".$api->getErrorMessage( )."\n";
exit;
}
$nom = $response->getElement(array(0));
$user_id = $nom->getAttribute('id');
#
# Get user's most recent photos
#
if (!$response)
{
print "Error getting most recent photo: ".$api->getErrorMessag
exit;
}
$photo = $response->getElement(array(0,0));
$photo_id = $photo->getAttribute('id');
$photo_secret = $photo->getAttribute('secret');
$photo_server = $photo->getAttribute('server');
#
# Formulate URL to the photo (image)
#
$imgUrl = "http://static.flickr.com/$photo_server/{$photo_id}_{$ph
#
# Formulate URL to the photo's Flickr page
#
$pageUrl = "http://www.flickr.com/photos/$user_id/$photo_id/";
#
# Get photo info
#
$response = $api->callMethod('flickr.photos.getInfo',
array( 'photo_id' => $photo_id ));
if (!$response)
{
print "Error getting most recent photo: ".$api->getErrorMessag
exit;
}
#
# Get title
#
$photo = $response->getElement(array(0));
$title = $photo->getElement(array(1));
$title = $title->content;
#
# Get date uploaded
#
$dateuploaded = $photo->getAttribute('dateuploaded');
$ltime = localtime((int) $dateuploaded, 1);
$datestr = $dateuploaded;
#
# Join tags into a single string
#
$tags = $photo->getElement(array(8));
$n = 0;
$taglist = '';
foreach ($tags->children as $tag)
{
if ($n++ > 0)
$taglist .= ', ';
$taglist .= $tag->content;
}
#
# Output HTML page containing URL to photo, image, and tags.
#
print <<<EOT
<html>
<head>
<title>Sample Photo Page</title>
</head>
<body>
<center>
The latest from $username...<br>
<a href="$pageUrl"><img src="$imgUrl" /></a><br>
Title: $title<br>
Uploaded: $datestr<br>
$taglist
</center>
</body>
</html>
EOT;
?>
T his next program is a port of the previous one with exac tly the
s ame features . T he only differenc e is that it us es phpFlickr,
whic h is a higher- level A P I kit than PEAR::Flickr_API. I think
you'll find the c ode eas ier to unders tand. I n addition, the s upport
web s ite for phpFlickr c ontains c ons iderably more doc umentation
and a few ac tual c ode examples . H uzzah!
<?
require_once("phpFlickr.php");
$api_key = 'your_api_key';
# This is a good spot to enable caching -- see the ransom note hac
# in Chapter 7 for an example
#
# Get user's ID
#
$username = 'jbum';
if (isset($_GET['username']))
$username = $_GET['username'];
$user_id = $api->people_findByUsername($username);
#
# Get user's most recent photo
#
$photos = $api->people_getPublicPhotos($user_id,NULL,1);
$photo = $photos['photo'][0];
$photo_id = $photo['id'];
$photo_secret = $photo['secret'];
$photo_server = $photo['server'];
#
# Formulate URL to the photo (image)
#
$imgUrl = "http://static.flickr.com/$photo_server/{$photo_id}_{$ph
#
# Formulate URL to the photo's Flickr page
#
$pageUrl = "http://www.flickr.com/photos/$user_id/$photo_id/";
#
# Get Photo Info
#
$photoInfo = $api->photos_getInfo($photo_id);
#
# Get title
#
$title = $photoInfo['title'];
#
# Get date uploaded
#
$dateuploaded = $photoInfo['dateuploaded'];
$ltime = localtime($dateuploaded, 1);
$datestr = $dateuploaded;
$datestr = sprintf('%4d-%02d-%02d %2d:%02d',
$ltime['tm_year']+1900,
$ltime['tm_mon']+1,
$ltime['tm_mday'],
$ltime['tm_hour'],
$ltime['tm_min']);
#
# Join tags into a single string
#
$tags = $photoInfo['tags'];
$n = 0;
$taglist = '';
foreach ($photoInfo['tags']['tag'] as $tag)
{
if ($n++ > 0)
$taglist .= ', ';
$taglist .= $tag['_value'];
}
#
# Output HTML page containing URL to photo, image, and tags.
#
print <<<EOT
<html>
<head>
<title>Sample Photo Page</title>
</head>
<body>
<center>
The latest from $username...<br>
<a href="$pageUrl"><img src="$imgUrl" /></a><br>
Title: $title<br>
Uploaded: $datestr<br>
$taglist
</center>
</body>
</html>
EOT;
?>
$user_id = $api->people_findByUsername($username);
...
$photos = $api->people_getPublicPhotos($user_id,NULL,1);
...
$photoInfo = $api->photos_getInfo($photo_id);
T his makes the c ode more readable, but it als o means that
phpFlickr is c los ely tied to the partic ular s tate of the A P I at the
time it was releas ed. I f a new c all is added to the A P I , phpFlickr
won't s upport it until it is updated to add new glue. A t the
moment, however, things are pretty s table, and D an C oulter (the
developer of phpFlickr) has been pretty attentive to updates .
[Hack #37]
[Hack #38]
[Hack #41]
[Hack #47]
Hack 40. Authenticate Yourself
H owever, this als o means that if you are the author of an app,
and you are the only pers on us ing the app, you'll s till need to
jump through the hurdle of giving your app permis s ion to ac c es s
your own photos . A t the time of this writing, Flic kr's older,
eas ier- to- us e authentic ation mec hanis m s till works : you c an
pas s your email addres s and pas s word as parameters to any
Flic kr A P I c all that requires authentic ation. But this method is
c urrently being phas ed out, bec aus e it is n't very s ec ure.
Flic kr is now phas ing in a more c umbers ome but more s ec ure
authentic ation A P I . T his hac k s hows a relatively s imple way to
authentic ate your own apps , us ing this new A P I , for your own
private us e. T his method involves only a tiny bit of s c ripting and
is us eful for s ituations in whic h you are the only one who will be
us ing the app.
I f you want to authentic ate us ers other
than yours elf, s ee [Hack #41] .
Authentication Modes
Web Applications
Desktop Applications
I ns tead, the app reques ts the frob before the us er is s ent to the
Flic kr- hos ted permis s ions page, us ing the Flic kr A P I
flickr.auth.getFrob method. T his way, when the us er grants
permis s ion on Flic kr, the app already has all the information it
needs to generate an authentic ation token.
Mobile Applications
Getting Started
Firs t, get an A P I key for your app, if you haven't already. Sign in
to Flic kr and go to the following U RL :
C lic k the A P I Keys link (under "Read thes e firs t:"), and then
c lic k the "A pply for your key online now" link. For more
information about getting an A P I key, s ee "A P I Keys and
Sec rets ," earlier in this c hapter.
A fter you get your A P I key, you'll need to get your s hared s ec ret
and authentic ation U RL . Reload the A P I s ervic es page
(http://www.flic kr.c om/s ervic es /api/) and c lic k the word "Yours "
on the line that s ays "A P I Keys (Yours )."
You'll s ee a lis t of all your A P I keys , one for eac h app, as s hown
in Figure 6 - 4 .
The Code
#!/usr/bin/perl
use Flickr::API;
use XML::Simple;
$auth_token = XMLin($response->{_content})->{auth}->{token};
print "auth_token: $auth_token\n";
To run the hac k, you'll need the information we c ollec ted in the
prec eding s teps . I n our example, the values are:
928c994908f02385d1d97a457003cb71
A P I key
8698bb062a08ca11
Shared s ec ret
248-818-201
M ini - token
928c994908f02385d1d97a457003cb71
A P I key
8698bb062a08ca11
Shared s ec ret
127122-92395db066e82035
A uthentic ation token
You c an rec ord this information direc tly in your app and us e the
app indefinitely, as long as you don't revoke your own
permis s ions .
See Also
[Hack #41]
[Hack #36]
Hack 41. Authenticate Users
A uthentic ating people is one of the more has s le- prone features
of the A P I . T his is why it's a good idea to us e an A P I wrapper: it
handles the nitty- gritty details .
T his hac k c reates a web applic ation that dis plays a few of a
us er's mos t rec ent photos . We'll us e authentic ation s o that we
c an dis play the us er's P rivate photos as well as P ublic photos .
auth.php
xml.php
PEAR/
T he phpFlickr arc hive als o inc ludes s ome additional files that
s erve as s ample c ode and are not s tric tly required for a
phpFlickr ins tallation. You s hould ins tall all of the prec eding files
and the PEAR/ direc tory to a loc ation where P H P c an find them,
s uc h as in the php_include path. You might find it s imples t, at
firs t, to keep thes e files in the s ame direc tory as the firs t tes t
applic ation you write.
Getting Started
Firs t, get a new A P I key for the new app, following the
ins truc tions in "A P I Keys and Sec rets ."
You'll s ee a lis t of all your A P I keys , one for eac h app, as s hown
in Figure 6 - 8 .
A fter c lic king the link, fill out the form, as s hown in Figure 6 - 9 .
The Code
C reate a file c alled tes tauth.php and add the following c ode:
<?php
// Configuration stuff
$flickrAPIKey = "your API key goes here";
$flickrSharedSecret = "your shared secret goes here";
// Parse parameters
$page = 1;
if (isset($_GET['page']))
$page = $_GET['page'];
$columns = 6;
if (isset($_GET['columns']))
$columns = $_GET['columns'];
$rows = 6;
if (isset($_GET['rows']))
$rows = $_GET['rows'];
?>
// Configuration stuff
$flickrAPIKey = "928c994908f02385d1d97a457003cb71";
$flickrSharedSecret = "8698bb062a08ca11";
N ow, upload both tes tauth.php and the modified vers ion of
auth.php to your web s erver. You're ready to tes t your app!
E nter the addres s of the P H P file in your web brows er's addres s
bar, like s o:
http://www.yourdomain.com/testauth.php
T he firs t time you do this , the routine f->auth() will notic e that
there is no authentic ation token for you and will redirec t you to
the Flic kr applic ation permis s ions page, whic h looks s omething
Figure 6 - 1 0 .
A fter you pres s the "O K, I 'll A llow I t" button, you'll be
redirec ted bac k to the auth.php applic ation. T he exTRa parameter
will be pas s ed bac k, s o that auth.php knows where to ultimately
redirec t you.
See Also
[Hack #40]
[Hack #14]
Hack 42. Build a Custom Upload Script
If the existing Flickr upload tools aren't your cup of tea, try
brewing your own upload script.
Say you perform a c ertain number of s teps for eac h photo that
you upload to Flic kr. With s ome automation, you s hould be able
to c ombine thos e s teps with the upload proc edure, s aving you
time in the proc es s . T his hac k s hows how to put together a
c us tom upload s c ript that res izes photos and adds a c opyright
notic e before s ending them off to Flic kr. You c an adapt it to s uit
your needs .
O n the A P I Key A uthentic ation Setup page, you'll find your key
and your s hared s ec ret, and you c an s pec ify a title, des c ription,
logo, U RL , and authentic ation type for your applic ation. Bec aus e
you're authentic ating an applic ation for yours elf only, you don't
need to worry too muc h about what you enter here. G ive your
applic ation a memorable name s uc h as "M y U pload Sc ript," and
c hoos e D es ktop A pplic ation as the A uthentic ation Type. C opy
your s hared s ec ret, and c lic k Save C hanges to s et the
authentic ation.
#!/usr/bin/perl
# get_auth_token.pl
# This script requests an authentication token for a user
# given a specific API key and shared secret.
#
# You can get a Flickr API key and shared secret and read the
# full documentation for the Flickr API at:
#
# http://www.flickr.com/services/api/
use strict;
use Flickr::API;
use XML::Simple;
use Digest::MD5 qw/md5_hex/;
my $auth_token = $flickr_xml->{auth}->{token};
die "Couldn't get authentication token!" unless defined $auth_toke
perl get_auth_token.pl
T he s c ript will c ontac t the Flic kr A P I and as s emble the U RL for
reques ting authorization. I t will then open a brows er window with
that U RL , and you'll need to log in and grant your applic ation
permis s ion to read and write photos .
The Code
T he following c ode looks for any photos in a s pec ial Flickr drop
folder, res izes the photos , adds a c opyright notic e to eac h of
them, and uploads them automatic ally. O nc e uploaded, the
photos are moved to a Flickr s ent folder. You'll need to s et the
$flickrdrop and $flickrsent variables to folders on your s ys tem.
#!/usr/bin/perl
# flickr_upload.pl
# This script loops through photos in a directory, resizes each
# photo to the set maximum size, adds a copyright notice to each
# photo, and uploads each photo to Flickr. You can also specify a
# number of tags to associate with each photo on the command line.
#
# Usage: flickr_upload.pl [tag] [tag] [tag]
#
# You'll need an auth token, which you can aquire by running the
# accompanying get_auth_token.pl script.
#
# You can get a Flickr API key and shared secret and read the
# full documentation for the Flickr API at:
#
# http://www.flickr.com/services/api/
use strict;
use Flickr::Upload;
use Image::Magick;
use File::Copy;
my $photopath = "$flickrdrop$photo";
my $width = $image->Get('width');
my $height = $image->Get('height');
if ($photoid ne '') {
# Tell the user this photo is at Flickr
print "Done!\n";
A s eac h photo in the folder is proc es s ed and s ent to Flic kr, the
s c ript s tores eac h photo's new Flic kr I D in the @IDs array. A t the
end of the proc es s , the s c ript builds a U RL that will let you edit
the title, des c ription, and tags of eac h of the newly uploaded
photos .
Windows us ers will s ee the page in their brows er, thanks to the
final system " start $flickrURL"; c ommand. I f you're working in
another environment, you might want to s imply print the U RL to
the c ommand prompt, like s o:
print $flickrURL;
Running the Hack
perl flickr_upload.pl
You c an als o s pec ify tags as you run the s c ript. For example, if
you know you jus t dumped a bunc h of photos of trees into the
Flic kr drop folder, you c ould automatic ally tag eac h photo like
this :
Building your own upload s c ript takes a bit of time, but if you c an
enc aps ulate photo proc es s ing and Flic kr uploading into one
s tep, you'll make up that time eas ily in the future. A nd you'll
have a s c ript that's tailor- made for you!
Chapter 7. Custom
Applications
H ac ks 4 3 - 5 0
H ac k 4 3 . M as h U p Your P hotos
T his c hapter will s how you what's pos s ible when you go beyond
the Flic kr A P I bas ic s into the realm of more fully realized
c us tom applic ations .
Hack 43. Mash Up Your Photos
T his hac k relies on the getP hotoL is t.pl s c ript [Hack #33] and
the getSnaps .pl s c ript [Hack #34] .
ImageMagick
I mageM agic k is a library that enables you to automate mos t
image- proc es s ing c hores nearly everything that you might
otherwis e do with P hotos hop or G imp.
#!/usr/bin/perl
use Image::Magick;
($infile, $outfile) = @ARGV; # read command-line arguments: infi
$image = Image::Magick->new; # create an image handle
$image->Read($infile); # load in the source image
$image->Write($outfile); # save it back out (in some other f
#!/usr/bin/perl
use Image::Magick;
$image = Image::Magick->new;
$image->Set(size=>"800x600");
$image->Read('xc:white');
$image->Annotate(text=>'Hello World', x=>50, y=>50);
$image->Write('hello.jpg');
Finally, here's a program that takes two exis ting images and
c ompos ites them together to c reate a third image (this is the
bas is of the c ollage program that we'll develop in a moment):
#!/usr/bin/perl
use Image::Magick;
$outimage = Image::Magick->new;
$outimage->Set(size=>"800x600");
$outimage->Read('xc:white');
$img = Image::Magick->new;
$img->Read("hello.jpg");
$outimage->Composite(image=>$img, x=>10, y=>10);
undef $img;
$img = Image::Magick->new;
$img->Read("hello.jpg");
$outimage->Composite(image=>$img, x=>410, y=>10);
undef $img;
$outimage->Write('hello2.jpg');
The Code
#!/usr/bin/perl -s
#
# makeCollage.pl - Jim Bumgardner
#
use Image::Magick;
$photolist = shift;
$collageName = shift;
die "makeCollage.pl [-big] <photolist_file> [collagename]\n" if !$
require "$photolist";
$outimage = Image::Magick->new;
$outimage->Set(size=>"${outW}x${outH}");
$outimage->Read('xc:black');
$dirname = $photolist;
$dirname =~ s/\.ph// if $dirname =~ /\.ph$/;
$n = 0;
$img->Resize(geometry=>'200x200') if $big;
$mask->Read("xc:$mcolor");
$img->Rotate(degrees=>$rot,color=>'black');
$mask->Rotate(degrees=>$rot,color=>'black');
$outimage->Write("collage$suffix.png");
# done
getSnaps.pl fubuki_macro
Finally, we'll exec ute the c ollage s c ript we c reated in this hac k:
makeCollage.pl fubuki_macro
$v = int(rand( )*256);
$mcolor = sprintf '#%02x%02x%02x', $v, $v, $v;
$mask = Image::Magick->new;
$mask->Set(size=>"${w}x${h}");
$mask->Read("xc:$mcolor");
T he c olor of the mas k determines the opac ity of the image that
is being c ompos ited. I f the mas k is white (#FFFFFF), the image is
fully opaque. I f the mas k is blac k (#000000), the image is
trans parent. By us ing a range of random values for the mas k
c olor from blac k to white, we get a variety of opac ities in the final
image, whic h produc es a more impres s ionis tic res ult.
$x = rand( )*($outW-$w);
$y = rand( )*($outH-$h);
srand(27);
I f you want a high- res olution vers ion, download the larger
images and us e them, like s o:
[Hack #33]
[Hack #34]
[Hack #49]
Hack 44. Find the Dominant Color of an
Image
To run the s c ripts in this hac k, you'll need the following two
modules :
Image::Magick
Data::Dumper
The Code
#!/usr/bin/perl -s
#
# samplePhoto.pl - Jim Bumgardner
#
use Image::Magick;
$photoname = shift;
die "samplePhoto.pl <photoname>\n" if !$photoname;
my $image = Image::Magick->new;
$err = $image->Read($photoname);
die $err if $err;
my ($w,$h) = $image->Get('width','height');
$image->Resize(geometry=>'1x1');
($r,$g,$b) = $image->GetPixels(x=>0,y=>0,width=>1,height=>1,normal
undef $image;
$colorspec = sprintf "#%02x%02x%02x", $r, $g, $b;
$textcolor = $g < 128? 'white' : 'black';
print <<EOT;
<html><body>
<table><tr>
<td><img src="$photoname" /></td>
</tr><tr>
<td bgcolor=$colorspec>
<font color=$textcolor>
R: $r<br>
G: $g<br>
B: $b<br>
</font>
</td></tr></table>
</body></html>
EOT
# end of script
T he s ec ond s c ript rec ords c olor information for a large c ollec tion
of photos , us ing a photo lis t c reated by the getP hotoL is t.pl
s c ript [Hack #33] . Save this s c ript as s ampleSnaps .pl:
#!/usr/bin/perl -s
#
# sampleSnaps.pl - Jim Bumgardner
#
use Image::Magick;
use Data::Dumper;
$Data::Dumper::Terse = 1; # avoids $VAR1 = * ; in dumper output
$Data::Dumper::Indent = $verbose? 1 : 0; # more concise output
$photolist = shift;
$dirname = shift;
die "sampleSnaps.pl <photolist_file> [dirname]\n" if !$photolist;
require "$photolist";
@sampledPhotos = ( );
$nbrSampled = 0;
$firstPhoto = $photos[0];
$suffix = '_t' if !$suffix;
my $image = Image::Magick->new;
$err = $image->Read($fnam);
if ("$err") {
warn "$err";
next;
}
($w,$h) = $image->Get('width','height');
$x = $image->Resize(geometry=>'1x1');
($r,$g,$b) = $image->GetPixels(x=>0,y=>0,width=>1,height=>1,norm
undef $image;
($photo->{r},$photo->{g},$photo->{b}) = ($r,$g,$b);
++$nbrSampled;
print "$nbrSampled...\n" if $nbrSampled % 50 == 0;
}
$ofname = "$dirname/samples.ph";
I nteres tingly, I 've found that if you take a large c ollec tion of
digital photographs from Flic kr and average the c olors together,
it tends to produc e a dull brown or orange c olor, rather than gray,
as you might expec t. Why this is s o, I 'm not s ure. Some s ay it
has s omething to do with the qualities of indoor lighting and flas h
photography. C omputer graphic s guru Kevin Bjorke offers a more
pros aic explanation: "I t's the c olor of dirt and people."
getPhotoList.pl aardvark
getSnaps.pl aardvark
sampleSnaps.pl aardvark
@photos = (
# etc...
sub RGBtoHSV($$$)
{
my ($r,$g,$b) = @_;
my $max = $r > $g? $r : $g;
$max = $max > $b? $max : $b;
my $min = $r < $g? $r : $g;
$min = $min < $b? $min : $b;
my $v = $max;
my $s = ($max != 0)? ($max-$min)/$max : 0;
my $h;
if ($s == 0) {
$h = 0; # undefined, actually
}
else {
my $d = $max - $min;
if ($r == $max) {
$h = ($g - $b)/$d;
}
elsif ($g == $max) {
$h = 2 + ($b-$r)/$d;
}
elsif ($b == $max) {
$h = 4 + ($r-$g)/$d;
}
$h *= 60;
if ($h < 0) {
$h += 360;
}
}
return ($h,$s,$v);
}
To inc orporate this into the s ampleSnaps .pl s c ript, add the
func tion to the bottom of the s c ript. T hen, after the line that
generates the RG B values :
($r,$g,$b) = $image->GetPixels(x=>0,y=>0,width=>1,height=>1,norm
you c an c onvert them to H SV values :
($h,$s,$v) = RGBtoHSV($r,$g,$b);
For an exc ellent introduc tion to c olor s pec ific ation and image
c oding, c hec k out the C olor FA Q :
See Also
[Hack #33]
[Hack #34]
[Hack #43]
[Hack #49]
Hack 45. Make a Color Picker
M os t us ers quic kly gras p the bas ic c onc ept of "point at a c olor,
s ee pretty pic tures " and have a lot of fun playing with it. M any
artis ts and des igners have told me they find this a us eful
interfac e for s earc hing for photos that matc h a partic ular palette.
To view the c olor pic ker, you'll need a web brows er with a Flas h
plug- in c apable of dis playing Flas h 6 movies or later.
The Code
T his P erl s c ript is res pons ible for c onverting image data from
P erl s yntax into A c tionSc ript s yntax, s o we c an inc lude the data
in a Flas h movie.
C reate a new text file c alled makeFlas hDB.pl and enter the
following P erl c ode:
#!/usr/bin/perl -s
#
# Convert Perl Photo List to Flash/ActionScript list for use in Co
# - Jim Bumgardner
#
$photolist = shift;
$dirname = shift;
$dirname = $photolist if !$dirname;
$dirname =~ s/\.ph// if $dirname =~ /\.ph$/;
$ifname = "$dirname/samples.ph";
require "$ifname";
$poolname = $dirname;
$n = 0;
foreach $photo (@photos)
{
print OFILE ",\n" if $n;
printf OFILE "{r:%d,g:%d,b:%d,owner:'%s', secret:'%s', server:%d
int($photo->{r}*255.999), int($photo->{g}*255.999), int($
$photo->{owner}, $photo->{secret},$photo->{server}, $phot
++$n;
}
print OFILE "\n];\n";
close OFILE;
Running the Hack
A c olor pic ker c an be made for any c ollec tion of photos on Flic kr,
but it works bes t if the c ollec tion has more than 5 0 0 photos .
H owever, you will als o enc ounter performanc e problems if the
number of photos exc eeds 2 0 ,0 0 0 or s o. T he more photos there
are in the databas e, the longer it will take to identify photos by
c olor and to load the Flas h movie.
T his hac k will make a c olor pic ker us ing the photos in the Stoc k
Repos itory group pool at http://www.flic kr.c om/groups /s toc k/. A t
las t c ount, this group had 1 ,6 5 8 photos in the pool, whic h is a
good number for a c olor pic ker.
http://static.flickr.com/1/buddyicons/49503068103@N01.jpg?10915605
T hen, rename the res ulting file to make it a little eas ier on the
eyes :
You now have a file c alled s tock.ph, whic h c ontains a des c ription
of eac h photo in the Stoc k Repos itory pool.
Adding stock/48828925_t.jpg...
Adding stock/20569503_t.jpg...
Adding stock/30148198_t.jpg...
Adding stock/24745811_t.jpg...
Adding stock/56897033_t.jpg...
Adding stock/40633875_t.jpg...
Adding stock/51200366_t.jpg...
Adding stock/26152510_t.jpg...
[etc...]
1610 added
You now mus t us e the s c ript you jus t c reated, makeFlas hDB.pl, to
c onvert the information in s tock/s amples .ph (whic h is in P erl
s yntax) to a file with A c tionSc ript s yntax (s tock.as ), whic h you'll
be able to us e in the Flas h movie:
poolname='stock';
imgdb = [
{r:179,g:170,b:104,owner:'74112673@N00', secret:'f0d1bae053', serv
{r:70,g:55,b:52,owner:'73624728@N00', secret:'ffb2f98e7d', server:
{r:131,g:129,b:109,owner:'46172547@N00', secret:'a396cdca40', serv
{r:139,g:137,b:135,owner:'86497205@N00', secret:'44607ffa2d', serv
[etc...]
#include "myphotolist.as"
doPick( );
#include "myphotolist.as"
to read like this , s ubs tituting the name of the A c tionSc ript
databas e file you jus t c reated:
#include "stock.as"
I f you like the res ults , s elec t the P ublis h c ommand on the File
menu to c reate a Flas h movie file. T his will c reate two files ,
s tockPickr.s wf and s tockPickr.html, whic h you c an upload to your
own web s erver.
A lthough not printed in this book, the c ode for the c olor pic ker
interfac e is c ontained within colrpickr.as and is inc luded in the
Jims FlickrScripts .zip arc hive.
I n addition to working with Flic kr, the c ode is des igned s uc h that
it c an eas ily be modified to work with other web- bas ed image-
arc hiving s ervic es .
T he two key routines that you will need to modify to work with
other s ervic es are GetThumbUrl(), whic h c reates a U RL to a
thumbnail image, and GetExternalUrl(), whic h c reates a U RL to
the s ite where the image is hos ted. T hes e routines eac h rec eive
a s ingle argument, whic h is a rec ord c orres ponding to the photo:
// These two routines can be modified to make the colr pickr work
// with other image archives...
GetThumbUrl = function(imgRec)
{
return 'http://static.flickr.com/' +
imgRec.server + '/' + imgRec.id + '_' + imgRec.secret + '_
}
GetExternalUrl = function(imgRec)
{
return 'http://www.flickr.com/photos/' + imgRec.owner +
'/' + imgRec.id;
}
See Also
[Hack #33]
[Hack #34]
[Hack #44]
Hack 46. Make a Motivational Poster and
Other Swag
Flickr Toys
Badge Maker
Calendar
Flickr Uploadr
Fortune
Motivator
Slides how
M any of the toys produc e images that make great gifts for
birthdays , retirement parties , and other oc c as ions that c all for
s omething a little s pec ial.
When you pres s the M otivate button, FD 's s c ript will do s ome
proc es s ing and then produc e an attrac tive and ins piring res ult
like the one s hown in Figure 7 - 1 0 .
The code
<?php
// Configuration stuff
$flickrAPIKey = "<your_api_key>";
require_once("phpFlickr.php");
$f = new phpFlickr($flickrAPIKey);
if (isset($_GET['button'])) {
// Create a 750x600-pixel canvas, on which we'll draw everythi
$canvas = imagecreatetruecolor(750, 600);
You will need to edit the firs t line at the top of the file, replac ing
<your_api_key> with your ac tual A P I key. T hen, upload the s c ript
to your web s erver.
See Also
[Hack #43]
[Hack #47]
[Hack #50]
Hack 47. Make a Ransom Note
The Code
C reate a file c alled rans omNote.php and add the following c ode:
<?php
// Configuration stuff
$flickrAPIKey = "your API key";
$cachingenabled = true;
$dbUser = "user"; //database user here
$dbPass = "pass"; //database password here
$dbAddress = "localhost"; //location of database
$dbName = "dbName"; //name of database, will create one if it does
$size = 'thumbnail';
if (isset($_GET['size']))
$size = $_GET['size'];
$len = strlen($phrase);
$ltrphotos = array( );
?>
<html>
<head>
<title>ransom note</title>
</head>
<body>
<center>
<?php
?>
</center>
</body>
</html>
$cachingenabled = true;
$dbUser = "user"; //database user here
$dbPass = "pass"; //database password here
$dbAddress = "localhost"; //location of database
$dbName = "dbName"; //name of database, will create one if it does
I f you do not wis h to us e c ac hing, turn it off by replac ing this
line:
$cachingenabled = true;
with this :
$cachingenabled = false;
To run the hac k, upload the edited s c ript to your web s erver, and
invoke it by typing the U RL in your brows er's addres s bar:
http://www.yourdomain.com/ransomNote.php
http://www.yourdomain.com/ransomNote.php?phrase=I+love+kittens
You c an als o s pec ify different photo s izes by us ing the size
parameter. H ere are the available c hoic es (from s malles t to
larges t):
square
thumbnail
small
medium
large
original
For example:
http://www.yourdomain.com/ransomNote.php?phrase=teensy+photos&size
[Hack #41]
[Hack #13]
Hack 48. Make a Slider Puzzle
To view the res ults , you'll als o need a web brows er with a Flas h
plug- in c apable of dis playing Flas h 7 movies or later.
imgUrl
TD
The Code
<?php
ini_set("error_reporting ", E_ALL);
// Configuration stuff
$flickrAPIKey = "your API key";
$cachingenabled = true;
$dbUser = "user"; //database user here
$dbPass = "pass"; //database password here
$dbAddress = "localhost"; //location of database
$dbName = "dbname"; //name of database, will create one if it does
$per_page = 6;
// Parse parameters
$page = mt_rand(2,3700);
if (isset($_GET['page']))
$page = $_GET['page'];
$idx = mt_rand(1,$per_page);
if (isset($_GET['idx']))
$idx = $_GET['idx'];
$TD = 5;
if (isset($_GET['TD']))
$TD = $_GET['TD'];
$group_id = '52242140489@N01';
if (isset($_GET['group_id']))
$group_id = $_GET['group_id'];
$photos = $f->groups_pools_getPhotos($group_id,NULL,NULL,$per_page
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "ht
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-88
<title>Flickr Puzzle</title>
</head>
<body>
<center><table><tr>
<td valign=bottom width=100><a href="http://www.krazydad.com/flick
<?php
$i = 1;
foreach ($photos['photo'] as $photo) {
echo "<td align=center width=81><a href=http://www.krazydad.co
"&TD=$TD&page=$page><img border='0' width=75 height=75 al
$f->buildPhotoURL($photo, 'square') . "></a><br><a href="
buildPhotoSourceURL($photo) . ">flickr</a></td>";
if($i == $idx)
$imgUrl = $f->buildPhotoURL($photo, 'medium');
$i++;
}
print <<<EOT
<td valign=bottom width=100 align=right><a href="http://www.krazyd
<a href="http://www.krazydad.com/flickrPuzzle/index.php?idx=$idx&T
<a href="http://www.krazydad.com/flickrPuzzle/index.php?idx=$idx&T
</td></tr></table>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/fla
width="500" height="500" id="flickrPuzzle" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="flickrPuzzle.swf?imgUrl=$imgUrl&TD=$TD"
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<embed src="flickrPuzzle.swf?imgUrl=$imgUrl&TD=$TD"
quality="high" bgcolor="#FFFFFF" width="500" height="500" name="f
align="middle" allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
EOT;
?>
</center>
</body>
</html>
http://www.yourdomain.com/flickrPuzzle.php
group_id
page
idx
T he partic ular image on the page (from 1 - 6 ) to us e to
make the puzzle.
TD
For example:
http://www.yourdomain.com/flickrPuzzle.php?page=2&idx=4
A lthough it's not inc luded here, you'll find the s ourc e c ode for
the 2 K Flas h movie that animates the puzzle at
http://www.krazydad.c om/flic krP uzzle/.
See Also
[Hack #50]
[Hack #41]
Hack 49. Make a Photo Mosaic
Using Flickr, any portrait can be more than the sum of its parts.
P hoto mos aic s c ompos ite artworks in whic h the mos aic tiles are
thems elves photographs were firs t invented by J os eph Franc is at
the R/G reenberg ad agenc y in the early 1 9 9 0 s . T hey weren't
popularized until the late `9 0 s , though, when Robert Silver, a
M as ter's s tudent at the M I T M edia L ab, c ame up with the idea
independently. Knowing he had a good thing on his hands , Silver
trademarked the name P hotoM os aic , applied for a patent, formed
his own c ompany, and s tarted s elling them. Soon, Silver's
beautiful and impres s ive mos aic s were s howing up in books , on
pos ters , and on magazine c overs .
N ot s o long ago, photo mos aic s would have been hard to make
on c heap des ktop c omputers at home. You needed fas t
proc es s ing s peeds , very large dis k c apac ity, and thous ands of
photographs to work with. T hes e days , the c heapes t des ktop
P C s have all the proc es s ing power and dis k c apac ity you need,
and s ervic es s uc h as Flic kr provide the final mis s ing ingredient:
a huge library of images .
To build a photo mos aic , the s oftware s elec ts tiles from a large
pool of c andidate images . T he tiles are pic ked s o that eac h one
matc hes an area of a target image. For eac h tile, the s oftware
pic ks the c andidate image that is the c los es t matc h, typic ally by
c omparing the c olor dis tanc e in E uc lidean s pac e. So, a
c andidate image that is pinkis h would be c hos en for a tile
repres enting a red area over another c andidate image that is
green, bec aus e pink is c los er to red. T he c los er the tiles matc h,
the more the final mos aic will res emble the target image.
A number of fac tors affec t how well your photo mos aic s will c ome
out. L et's take a look at s ome of the things you'll need to
c ons ider.
I f you are us ing off- the- s helf mos aic s oftware, you might need to
res ize the target image down to a s maller s ize s o that the
mos aic s oftware does n't take forever trying to make a huge
image.
P hoto mos aic s are mos t effec tive when the s ubjec t matter of the
tiles has s omething to s ay (des c riptively, affec tionately,
ironic ally) about the target image. T hous ands of photo mos aic s
portraits have been c ons truc ted from generic s toc k photos of
s eas c apes and barns . T hes e are tec hnic ally impres s ive, but
ultimately meaningles s , unles s the s ubjec t of the portrait is a
s ailor or a farmer.
G enerally, the more tiles you have to c hoos e from, the more
ac c urate the res ult will be. O n the other hand, you might like the
res ults you get when there aren't many c hoic es available; this
tends to produc e more abs trac t images , and s ometimes
ac c idents c an be c ool.
To run the s c ript in this hac k, you'll need the Image::Magick P erl
module, whic h provides an A P I for the powerful I mageM agic k
image- proc es s ing library. You c an find it at
http://www.imagemagic k.org, or you c an download it from C P A N .
The Code
H ere's my s c ript for making photo mos aic s with Flic kr photos ,
us ing my Image::Mosaic module. C reate a file c alled makeMos aic.pl
and enter the following c ode (or grab the lates t vers ion from the
arc hive mentioned in the previous s ec tion):
#!/usr/bin/perl -s
#
# sub-sampling photo mosaic - Jim Bumgardner
#
# this script uses a subset of images from a larger set
# to make a mosaic against a target image
#
# work on reducing globals - store shared variables in an object..
use Image::Mosaic;
use Image::FlickrSet;
$photolist = shift;
$basepic = shift;
$max_images = shift;
$imagedir = shift;
$syntax = <<EOT;
pmosiac_subset.pl [options] <photolist> <basepic> [<max_images>]
Options:
-dupesOK Allow duplicate tiles
-noborders Reject images with solid-color borders or over 2:1
-noflops Images may not be swapped horizontally
-reso=\# Subsamples per photo - default = 7
-cellsize=\# Size of tiles - default = 20
EOT
require "${photolist}";
#
# these are all command-line options
#
$reso = 7 if !$reso; # number of subsamples per tile = reso x res
$cellsize = 20 if !$cellsize;
$cellsize = 100 if $big;
$doflops = 1 if !$noflops && !$noflips;
my $moz = Image::Mosaic->new({reso=>$reso,
max_images=>$max_images,
imageset=>$imageset,
basepic=>$basepic,
noborders=>$noborders,
doflops=>$doflops,
cellsize=>$cellsize,
verbose=>1
});
$moz->generate_mosaic( );
getPhotoList.pl -u fubuki
getSnaps.pl fubuki.ph
By default, the s c ript produc es a low- res olution vers ion of the
mos aic . I generally try a few different vers ions (experimenting
with editing the target image and altering the number of tiles ) till
I find one I like. I f you like the res ult, you c an produc e a high-
res olution mos aic us ing the -big option:
How It Works
4. L oads in the s elec ted tiles and builds a c ompos ite image
from them. D uring this s tep, if the -big option was
employed, larger vers ions of the s elec ted tiles will be
downloaded by the Image::FlickrSet module, as
nec es s ary.
A lthough s ome people might feel that photo mos aic s are pas s é,
there is s till enormous potential for innovations in making them.
For example, while exis ting photo mos aic s oftware produc es
mos aic s with s quare or rec tangular tiles , there is c ertainly no
reas on why photo mos aic s have to have s quare tiles on a
rec tangular grid.
Finally, photo mos aic s do not need to be s tatic piec es of art that
hang on a wall. You c an build an interfac e, us ing Flas h or A jax,
that will make your mos aic interac tive, perhaps providing
individual photo c redits for the tiles or making the tiles c ome to
life. I 've c reated s uc h interfac es for my C overP op web s ite
(http://www.c overpop.c om), whic h c ontains interac tive mos aic s
built from various s ourc es . See the C overP op FA Q
(http://www.c overpop.c om/faq/) for more information about
building interfac es for interac tive mos aic s .
See Also
[Hack #33]
[Hack #34]
[Hack #44]
[Hack #43]
Hack 50. Make a Slideshow
C reate a text file c alled s lides how_s cript.as and add the following
A c tionSc ript c ode:
flickrSnapAry = _root.flickrSnaps.split(',');
doNextSlide = function( )
{
clearInterval(this.intH);
curSlide = (curSlide + 1) % flickrSnapAry.length;
this.altSlot.doLoad(curSlide);
}
fadeInStep = function( )
{
var r = (getTimer( ) - this.fxStart)/this.fxDuration;
if (r >= 1) {
r = 1;
clearInterval(this.intH);
this.intH = setInterval(this, "doNextSlide", timeBetweenSlides
}
// This applies an ease in/out to the fade effect
r = r*r*(3-2*r);
this._alpha = r*100;
this.altSlot._alpha = (1-r)*100;
// This next line provides the barn-door effect
// Comment it out for a more standard-looking
// cross-fade effect
this._xscale = r*100;
}
doFadeIn = function(duration)
{
this.fxStart = getTimer( );
this.fxDuration = duration;
this.fxStep = fadeInStep;
this.intH = setInterval(this,"fxStep",1000/30);
}
handleLoadInit = function(target)
{
// Center the slide
this._x = (Stage.width - target._width)/2;
this._y = (Stage.height - target._height)/2;
this.doFadeIn(fadeTime);
}
doLoad = function(slideNbr)
{
if (_root.debug)
_root.errMsg.text = "loading " + slideNbr + ' ' + flickrSnapAr
var fVars = flickrSnapAry[slideNbr].split('/');
this._alpha = 0;
this.itsURL = 'http://static.flickr.com/' + fVars[0] + '/' +
fVars[1] + '_' + fVars[2] + '.jpg';
this.itsLoader.loadClip(this.itsURL, this.loadee);
}
Dimens ions
5 0 0 x 5 0 0 pixels
Background Color
Blac k
Frame Rate
3 0 fps
Selec t the firs t frame of the movie on the timeline, and then open
the A c tionSc ript editing window by s elec ting Window
D evelopment P anels A c tions from the menu.
I n the A c tionSc ript window, enter the following one- line s c ript,
whic h c aus es the s c ript you jus t c reated to be inc luded:
#include "slideshow_script.as"
T hat's about all the Flas h authoring you need to do. A s you c an
s ee, mos t of the interes ting s tuff is in the A c tionSc ript file.
The Code
C reate a new text file c alled tes tSlides how.php and enter the
following P H P c ode:
<?php
ini_set("error_reporting ", E_ALL);
// Configuration stuff
$flickrAPIKey = "your API key goes here";
$flickrSharedSecret = "your shared secret goes here";
// Parse parameters
$page = 1;
if (isset($_GET['page']))
$page = $_GET['page'];
$per_page = 30;
if (isset($_GET['per_page']))
$per_page = $_GET['per_page'];
$fade_time = 2000;
if (isset($_GET['fade_time']))
$fade_time = $_GET['fade_time'];
$flickr_snaps = '';
$i = 0;
foreach ($photos['photo'] as $photo) {
if ($i++)
$flickr_snaps .= ',';
$flickr_snaps .= $photo['server'] . '/' . $photo['id'] . '/' .
}
print <<<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "ht
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-88
<title>slideshow</title>
</head>
<body bgcolor="#000000" color=white><?php
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/fla
width="500" height="500" id="slideshow" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="slideshow.swf?fadeTime=$fade_time&flick
<param name="quality" value="high" />
<param name="bgcolor" value="#000000" />
<embed src="slideshow.swf?fadeTime=$fade_time&flickrSnaps=$flickr_
quality="high" bgcolor="#000000" width="500" height="500" name="s
align="middle" allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</body>
</html>
EOT;
?>
U pload tes tSlides how.php to your web s erver, into the s ame
loc ation where you uploaded the s lides how.s wf file.
To run the hac k, enter the addres s of tes tSlides how.php into your
web brows er's addres s bar:
http://www.yourdomain.com/testSlideshow.php
I f you have not yet been authentic ated, you'll s ee the Flic kr
permis s ions s c reen. O nc e you've granted permis s ion, the
s lides how s hould begin.
You c an modify the s lides how by pas s ing any of the following
parameters to the app:
per_page
fade_time
T his s pec ifies , in millis ec onds , how long the c ros s - fade
effec t las ts . T his partic ular parameter gets pas s ed into
the Flas h movie.
http://www.yourdomain.com/testSlideshow.php?per_page=10&page=4&fad
To keep things s imple, I 've written this s c ript to pas s only one
adjus table parameter, fade_time, to the Flas h movie, but I would
s ugges t adding a whole s lew of parameters s o you c an
c us tomize the s lides how to your liking.
See Also
[Hack #41]
[Hack #45]
Index
[B] [C] [D] [E] [F] [G] [I] [M] [O] [P] [R] [S] [T]
[U] [W] [Y ]
Index
[B] [C] [D] [E] [F] [G] [I] [M] [O] [P] [R] [S] [T]
[U] [W] [Y ]
Bookshelf Project
Index
[B] [C] [D] [E] [F] [G] [I] [M] [O] [P] [R] [S] [T]
[U] [W] [Y ]
command line
running hacks on
community, Flickr
Contact status
contacts
[B] [C] [D] [E] [F] [G] [I] [M] [O] [P] [R] [S] [T]
[U] [W] [Y ]
[B] [C] [D] [E] [F] [G] [I] [M] [O] [P] [R] [S] [T]
[U] [W] [Y ]
email
uploading photos to Flickr via
Index
[B] [C] [D] [E] [F] [G] [I] [M] [O] [P] [R] [S] [T]
[U] [W] [Y ]
Flickr
configuring privacy options for photos
setting up account
Tools page
Uploadr tool
Flickr address
choosing
Flickr community
contacts
groups
Friends status (contacts)
Index
[B] [C] [D] [E] [F] [G] [I] [M] [O] [P] [R] [S] [T]
[U] [W] [Y ]
Groups feature
[B] [C] [D] [E] [F] [G] [I] [M] [O] [P] [R] [S] [T]
[U] [W] [Y ]
[B] [C] [D] [E] [F] [G] [I] [M ] [O] [P] [R] [S] [T]
[U] [W] [Y ]
Mac OS X
Terminal
Macromedia Flash Player
more program
Index
[B] [C] [D] [E] [F] [G] [I] [M] [O] [P] [R] [S] [T]
[U] [W] [Y ]
Organizr tool
Index
[B] [C] [D] [E] [F] [G] [I] [M] [O] [P] [R] [S] [T]
[U] [W] [Y ]
permissions
PHP
online manual
PHP scripts 2nd
privacy settings 2nd
[B] [C] [D] [E] [F] [G] [I] [M] [O] [P] [R] [S] [T]
[U] [W] [Y ]
RSS feeds
Index
[B] [C] [D] [E] [F] [G] [I] [M] [O] [P] [R] [S] [T]
[U] [W] [Y ]
scripts
scrolling, controlling for script output
sets, photo
sharing photos 2nd
Flickr community
permissions
limiting to contacts
slideshows
view ing photo sets as
sorting photos on Flickr
Index
[B] [C] [D] [E] [F] [G] [I] [M] [O] [P] [R] [S] [T]
[U] [W] [Y ]
tags
RSS feeds for
Terminal (Mac OS X)
Tools page
Index
[B] [C] [D] [E] [F] [G] [I] [M] [O] [P] [R] [S] [T]
[U] [W] [Y ]
URLs
Flickr address for photo sharing
Index
[B] [C] [D] [E] [F] [G] [I] [M] [O] [P] [R] [S] [T]
[U] [W] [Y ]
web browser
uploading photos to Flickr via
Windows
DOS command w indow
Uploadr program
Index
[B] [C] [D] [E] [F] [G] [I] [M] [O] [P] [R] [S] [T]
[U] [W] [Y]
Yahoo!
account, setting up
Hacks group