Save an image and generate Thumb with nodejs

Asked

Viewed 369 times

1

I am trying to burn an image to disk and after that generate a Thumb of the images that was saved.

To do this I saved normal the image in Base64 that was sent and in the callback of Fs.writeFile I call the function to generate the Thumb.

I’m trying to generate Thumb using the package imagemagick

const im = require('imagemagick');
const fs = require('fs');

const imagemCapa        = objetoFolder + "\\" + comando.imagemCapa;
const imagemCapaThumb   = objetoFolder + "\\capa_thumb.jpg";

//Grava no disco
fs.writeFile(imagemCapa, comando.imagemCapaBase64, 'base64', (err) => {
    if(err) console.log(err);

    //Thumb
    const optionsThumb = {
        srcPath: imagemCapa,
        dstPath: imagemCapaThumb,
        width: 262                                  
    };
    im.resize(optionsThumb, (err, stdout, stderr) => {
        if (err) console.log(err);
        console.log('Thumb gerado');
    });

});

I can write the image to disk but it’s not generating Thumb.

Who can help thank you beforehand! A hug.

  • You shouldn’t wear imagemCapa in time of capa.jpg? You’re always looking for the same image, not the one that was recorded. You may have folder issues too, you can explain which folder your file is in .js and in which folder the image is saved?

  • Opa @Sergio, I had put wrong. Has the variables that receive the path of the image that was saved and Thumb before, are the imageCapa and imageCapaThumb.

  • You get an error on the Node?

  • I don’t get it, that’s the problem... it saves the image, enters the callback of the Thumb generation but doesn’t save the Thumb in fact.

  • In the code that is in the question you have nothing to save the thumbnail. Do you know that or is that part you don’t know how to do?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.