Image search using webservices
Ive got an assignment to create an image gallery using flickr - this has to be done using keyword(s) entered by a user in a form, and the image gallery returned must be paginated and display a certain number of results per page. Each image in the gallery must also be a thumbnail.
Im graded based on how efficient, maintainable, consise and clear the code is..
Ive finished the assignment but i think it could be optimised alot better, these are the points that i might be lacking.
- All my code is in a single file (the form and the gallery code) - s开发者_运维知识库hould i separate this?
- Im not using oo at all, is there someway i can make use of it here?
- Im resizing the thumbnails using html length and width
thanks for any help
This question is really broad, and it seems like you want someone to write the code for you, which I won't do but I'll help point in the right direction.
First, Flickr has an API, I would reccomend checking that out.
http://www.flickr.com/services/api/
You are going to need a library to make thumbnails, you can do that quickly with GD
http://php.net/manual/en/book.image.php
As far as separating the code, it probably wouldn't be a bad idea. One file is great if its a few hundred lines, but if you have a lot going on, it doesnt hurt to separate files by their function (ex: scrape.php, resize.php etc.). That's mostly personal preference. Since you're being graded on maintainability and clarity I would suggest breaking it up.
At the risk of starting a flamewar, I would suggest making it OOP. If you want it to be clear and readable this will help a lot. Break it into classes and functions and group them in a logical manner so someone knows if they need to change something they have a good idea where to start. Document it well and this will help also.
My suggestion would be to create a class for each of these functions:
- Grab images from Flickr
- Store the metadata related to the images
- Resize the images
- Pull the information from the database
- Display the pages.
Try to keep the data functions separate from the presentation. Use a class to build your pages, and call another class to get the data. This is pretty general advise, but it's something you'll need to know when building future apps. This doesn't necessarily need to be full MVC, but separation of these tasks will make the code make more sense.
精彩评论