API: Get Flickr Photos by Orientation

I only want to receive landscape photos from Flickr, but I don't see any options that will allow me to do this. Does anyone know if there is a way?

+3


source to share


1 answer


In the response of the function, flickr.photos.search

you can specify a number of optional parameters, which are known as extras

. For each URL (in the format url_s,url_q

...) that you specify, you will receive the following information.

Sample JSON response

{
    ...
    "photos": { 
        "page": 1, 
        "pages": "478", 
        "perpage": 2, 
        "total": "4775", 
        "photo": [
            { 
                ...
                "longitude": 0, "accuracy": 0, "context": 0, "media": "photo",
                "media_status": "ready",
                "url_q": "https:\/\/farm4.staticflickr.com\/0000\/000_000_q.jpg",
                "height_q": "150",
                "width_q": "150",
                ...
            },
            { 
                ...
                "longitude": 0, "accuracy": 0, "context": 0, "media": "photo",
                "media_status": "ready",
                "url_q": "https:\/\/farm4.staticflickr.com\/0000\/000_111_q.jpg",
                "height_q": "150",
                "width_q": "150",
                ...
            },
        ] }, 
        "stat": "ok" 
};

      

If you need a URL-address for the photo size Q, will have attributes height_q

and width_q

. If width_q

greater than height_q

, the orientation of the landscape . If on the contrary, the orientation of the photo is portrait , otherwise it is a perfect square.



In Javascript, you can write a function like this:

function determinePhotoOrientation(width, height) {
    if (width > height) {
        return 'landscape';
    } else if (width < height) {
        return 'portrait';
    }
    return 'square';
}

      

If you are using a different language, you can do a similar function in that language to help you determine the orientation.

+4


source







All Articles