jimp-dev / jimp

An image processing library written entirely in JavaScript for Node, with zero external or native dependencies.
http://jimp-dev.github.io/jimp/
MIT License
14.07k stars 761 forks source link

read from url with custom headers #267

Closed rwpino closed 6 years ago

rwpino commented 7 years ago

Hello, I want to use your library to load my image from a remote server thru http with custom headers and converted into base64 string,It is possible do it right now?. if no will be super good if the method allow pass configurations headers

syzer commented 6 years ago

👍

syzer commented 6 years ago

@rwpino you can workaround by :

  1. send plain request with headers
  2. get the buffer and mime type
  3. and then jimp.read(buffer, mimetype)
hipstersmoothie commented 6 years ago

we need something line

phin({ url, compression: true, headers: {
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.46 Safari/537.36"
} }, (err, res) => {
  if (err === null) {
    cb(null, res, res.body);
  } else {
    cb(err);
  }
});

This will probably require a breaking change thought to feed in the options for phin

hipstersmoothie commented 6 years ago

@rwpino @syzer v0.5.2 has a new constructor option that allows you to pass the headers. Can you try it out for me?

await Jimp.read({ url: '...', headers: { ... } })
hipstersmoothie commented 6 years ago

confirmed that v0.5.2 solve this issue. Feel free to open another PR if you have further issues.