How to get static image url from flickr URL?
Asked Answered
C

6

35

Is it possible to get static image URL from the flickr URL via an api call or some script ?
For eg :
Flickr URL -> http://www.flickr.com/photos/53067560@N00/2658147888/in/set-72157606175084388/
Static image URL -> http://farm4.static.flickr.com/3221/2658147888_826edc8465.jpg

Courtship answered 26/11, 2009 at 12:5 Comment(2)
Yes, really old. But if you, like me, still end up here after googling, check out this link: flickr.com/services/api/misc.urls.htmlAntonioantonius
Ho i can extract your second url from first one?Longfellow
L
36

In your Flickr URL, the photo ID is 2658147888. You use flickr.photos.getSizes to get the various sizes of the photo available, and pick the url you want from that, depending on the size. There are several ways to access the API so please specify if you want more details for a particular language.

Lindsley answered 26/11, 2009 at 12:36 Comment(0)
S
63

With specifying extras=url_o you get a link to the original image:

https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=YOURAPIKEY&format=json&nojsoncallback=1&text=cats&extras=url_o

For downscaled images, you use the following parameters: url_t, url_s, url_q, url_m, url_n, url_z, url_c, url_l

Alternatively, you can construct the URL as described:

http://farm{farm-id}.staticflickr.com/{server-id}/{id}_{secret}.jpg
or
http://farm{farm-id}.staticflickr.com/{server-id}/{id}_{secret}_[mstzb].jpg
Skeen answered 28/5, 2014 at 12:4 Comment(1)
can you please order the parameters(url_t,url_s) based on image quality or atleast specify what each one doesMogul
L
36

In your Flickr URL, the photo ID is 2658147888. You use flickr.photos.getSizes to get the various sizes of the photo available, and pick the url you want from that, depending on the size. There are several ways to access the API so please specify if you want more details for a particular language.

Lindsley answered 26/11, 2009 at 12:36 Comment(0)
S
7

You can also access the original image using the photoId (number before the first underscore)

http://flickr.com/photo.gne?id=photoId

In your case it would be:

https://www.flickr.com/photo.gne?id=2658147888

Shauna answered 16/9, 2016 at 12:54 Comment(0)
B
5

Not sure if you can get it directly through a single API call, but this link explains how the urls for the images are contructed: link

Bac answered 26/11, 2009 at 12:11 Comment(1)
Thanks for the link. I prefer to construct the link by myself, because making an API call for every image is to slow for me.Elemental
F
3

Here's some code I wrote to retrieve metadata from a Flickr Photo based on its ID:

I first defined a javascript object FlickrPhoto to hold the photo's metadata:

function FlickrPhoto(title, owner, flickrURL, imageURL) {
    this.title = title;
    this.owner = owner;
    this.flickrURL = flickrURL;
    this.imageURL = imageURL;
}

I then created a FlickrService object to hold my Flickr API Key and all my ajax calls to the RESTful API.

The getPhotoInfo function takes the Photo ID as parameter, constructs the appropriate ajax call and passes a FlickrPhoto object containing the photo metadata to a callback function.

function FlickrService() {
    this.flickrApiKey = "763559574f01aba248683d2c09e3f701";
    this.flickrGetInfoURL = "https://api.flickr.com/services/rest/?method=flickr.photos.getInfo&nojsoncallback=1&format=json";

    this.getPhotoInfo = function(photoId, callback) {
        var ajaxOptions = {
            type: 'GET',
            url: this.flickrGetInfoURL,
            data: { api_key: this.flickrApiKey, photo_id: photoId },
            dataType: 'json',
            success: function (data) { 
                if (data.stat == "ok") {
                    var photo = data.photo;
                    var photoTitle = photo.title._content;
                    var photoOwner = photo.owner.realname;
                    var photoWebURL = photo.urls.url[0]._content;
                    var photoStaticURL = "https://farm" + photo.farm + ".staticflickr.com/" +  photo.server + "/" + photo.id + "_" + photo.secret + "_b.jpg";

                    var flickrPhoto = new FlickrPhoto(photoTitle, photoOwner, photoWebURL, photoStaticURL);
                    callback(flickrPhoto);
                }
            }
        };

        $.ajax(ajaxOptions);
    }
}

You can then use the service as follows:

var photoId = "11837138576";
var flickrService = new FlickrService();
flickrService.getPhotoInfo(photoId, function(photo) {
    console.log(photo.imageURL);
    console.log(photo.owner);
});

Hope it helps.

Firstling answered 28/1, 2015 at 19:10 Comment(0)
K
0

Below a solution without using flickr-apis, only standard Linux commands (actually I ran it on MS Windows with Cygwin):

  • Put your list of URLs in the tmp variable
  • If you are downloading private photos like me, the protocol will be https and you'll need to pass the authentication cookies to wget. I log on with a browser (Chrome) and exported the cookies file using an extension
  • If you access public URLs, just remove the parameter --load-cookies $cookies
  • The script downloads in the local folder the photos in their original format
  • If you want just the URL of the static image, remove the last command | xargs wget --load-cookies $cookies

Here the script, you can use it as a start for your explorations:

cookies=~/cookies.txt
root="https://www.flickr.com/photos/131469243@N02/"

tmp="https://www.flickr.com/photos/131469243@N02/29765108124/in/album-72157673986011342/
https://www.flickr.com/photos/131469243@N02/29765103724/in/album-72157673986011342/
https://www.flickr.com/photos/131469243@N02/29765102344/in/album-72157673986011342/"

while read -r url; do

    if  [[ $url == http* ]] ;
    then
        url2=$root`echo -n $url | grep -oP '(?<=https://www.flickr.com/photos/131469243@N02/)\w+'`/sizes/o
        wget -q --load-cookies $cookies -O - $url2 | grep -io 'https://c[0-9].staticflickr.com.*_o_d.jpg'  | xargs wget --load-cookies $cookies
    fi
done <<< "$tmp";
Kayser answered 19/1, 2017 at 20:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.