Skip to content

Instantly share code, notes, and snippets.

@videlais
Created June 26, 2016 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save videlais/7f325877c025bcdbb94490115d008d79 to your computer and use it in GitHub Desktop.
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
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