7

I can now get some data of picture from url, when I do something like this:

Jimp.read("https://someurl/04fc0d67a91bbd3b7e07.jpeg", function (err, image) {

        console.log(image.bitmap.data)
        res.end(image.bitmap.data)
    });

I get buffer

Buffer 3d 3b 20 ff 41 3f 24 ff 46 44 29 ff 4c 4a 2f ff 4e 4c 31 ff 4b 49 2e ff 47 43 2a ff 42 3e 25 ff 34 31 1a ff 2d 2a 13 ff 27 24 0f ff 25 22 0d ff 21 20 . >..

Is possible to resize image and then retrive that image in response?

Vladimir
  • 1,751
  • 6
  • 30
  • 52

1 Answers1

1

If you're looking for resizing you could try something like

jimp.read("https://i.imgur.com/2j12AxI.jpg").then(image => {

  //resize image using "contain" mode
  image.contain(100, 150);

  //retrieve image
  image.getBase64Async(jimp.MIME_JPEG).then(newImage => {
    let tag = document.createElement("img");
    tag.src = newImage;
    document.getElementById("img-container").append(tag)
  })
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jimp/0.16.1/jimp.js"></script>

<div id="img-container"></div>

This is just a basic demonstration of how to downscale with a given target width/height. By default, it adds black borders if your numbers don't match. There's another plugin to scale while keeping aspect ratio. The documentation looks pretty straightforward so you'll be able to find additional examples.

gekkedev
  • 562
  • 4
  • 18