-
-
Save videlais/7f325877c025bcdbb94490115d008d79 to your computer and use it in GitHub Desktop.
Retrieving and Editing Images from Flickr with flickr-sdk + JIMP on Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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