Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image from url ? #91

Closed
fabulousduck opened this issue Oct 18, 2016 · 1 comment
Closed

image from url ? #91

fabulousduck opened this issue Oct 18, 2016 · 1 comment

Comments

@fabulousduck
Copy link

is it possible in any way to give the image() function an url to an image from cloudinary or another such service ?

or would i have to download the image from cloudinary. pass it in. and delete it locally again?

@zhangyuanwei
Copy link
Owner

var http = require("http");
var images = require("images");

var url = 'http://www.lenna.org/full/l_hires.jpg';

http.get(url, function(res) {
    var buffer = [];
    var currentByte = 0;
    var countByte = res.headers['content-length'];
    if (res.statusCode === 200) {
        res.on("data", function(trunk) {
            buffer.push(trunk);
            currentByte += trunk.length;
            console.log(Math.floor(currentByte / countByte * 100) + "% " + currentByte + "/" + countByte);
        });
        res.on("end", function() {
            var data = Buffer.concat(buffer);
            var full = images(data).resize(512);
            var harf = images(full, 0, 0, 512, 512);
            harf.save("Lenna.jpg");
            console.log("Done!");
            // WARNING this picture contains nudity.
        });
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants