Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node resize image with url without saving image

I have a service that takes a FB image url as a param, checks it is a valid url that returns an image and then returns the url if all checks have passed. I would like to add a step to resize the image if those params are also passed in, and then return the resized image via url as I did before.

My experience with image manipulation is minimal to say the least, but my understanding so far is to use a library such as sharp, resize it, save the newly sized image somewhere and then return the new url to the image location.

That seems to be the most logical approach. But, I'm wondering what a possible solution would be if I do not want to host these resized images anywhere. Is there another way, or is my previous understanding on track with the way to go?

Example url from facebook would look like: https://scontent.xx.fbcdn.net/v/t1.0-9/16473924_10154471006092746_6242863207915608429_n.jpg?oh=4d7fb8fb162c0ff036810ee2969703f0&oe=5A25EE1C.

like image 646
johnny_mac Avatar asked Jul 17 '26 00:07

johnny_mac


1 Answers

Based on the questions title :

Node resize image with url without saving image

I think that you are trying to manipulate an image based upon a request to your 'service', and then send it back post-processed without having to store it and use disk space...

[JIMP] fetch, resize and return an image without saving to disk:

This example on requesting the server root '/', it fetches an image, resizes it and sends it back as a response without having to store it in disk.

const imgURL = "https://ichef.bbci.co.uk/news/660/cpsprodpb/37B5/production/_89716241_thinkstockphotos-523060154.jpg";
const express = require('express'); const app = express()
var Jimp = require("jimp")
app.get('/',function(req, res){
  Jimp.read(imgURL, function(err,img){
    if (err) throw err;
    img.resize(32, 32).getBase64( Jimp.AUTO , function(e,img64){
        if(e)throw e
        res.send('<img src="'+img64+'">')
    });
  });
});
app.listen(3000);
like image 83
EMX Avatar answered Jul 18 '26 17:07

EMX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!