Retrieving and Editing Images from Flickr with flickr-sdk + JIMP on Node.js
var Flickr = require('flickr-sdk'); | |
var Jimp = require("jimp"); | |
var flickr = new Flickr({ | |
"apiKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", | |
"apiSecret": "xxxxxxxxxxxxxxxx", | |
"accessToken": "xxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx", | |
"accessTokenSecret": "xxxxxxxxxxxxxxxx" | |
}); | |
// Refer to the flickr-sdk github page (https://github.com/flickr/flickr-sdk#responses) | |
// In this example, the API will search for images of "puppies" | |
flickr | |
.request() | |
.media() | |
.search("puppies") | |
.get() | |
.then(function (response) { | |
// Change the index. 0, in this example, will be the first photo found in the set | |
var photo = response.body.photos.photo[0]; | |
// Based on Flickr URLs (https://www.flickr.com/services/api/misc.urls.html) | |
var url = "https://farm" + photo.farm + | |
".staticflickr.com/" + photo.server + | |
"/" + photo.id + "_" + photo.secret + "_m.jpg"; | |
Jimp.read(url).then(function (image) { | |
// Do something with the image | |
}).catch(function (err) { | |
// Handle any errors | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment