Generate image ,pdf and Video Thumb using node js


      Using imagemagick Generate image thumb       


        var im = require('imagemagick');
        var image = random() + '.png';
        var imagepath = 'uploads/images_thumb/' + image;
        var pathToFile = path.join(__dirname, req.files[i].path),
            pathToSnapshot = path.join(__dirname, '/' + imagepath);
        im.resize({
            srcPath: pathToFile
              , dstPath: pathToSnapshot
              , width: 150
              , height: 150
              , quality: 0
              , gravity: "North"
        }, function (err, stdout, stderr) {
            if (err) {
                console.log(err);
            }
            console.log('resized image ', pathToSnapshot);
            //res.json(pathToSnapshot);
        });


    Using Gm Generate Pdf thumb   

     
     var gm = require('gm');
     var image = random() + '.png';
     var imagename = 'uploads/document_thumb/' + image;
     var pathToFile = path.join(__dirname, req.files[i].path),
     pathToSnapshot = path.join(__dirname, '/uploads/document_thumb/' + image);
        
     gm(pathToFile).thumb(150, // Width
                150, // Height
                pathToSnapshot, // Output file name
                40, // Quality from 0 to 100
                function (error, stdout, stderr, command) {
                    if (!error) {
                        console.log(command);
                    }
                    else {
                        console.log(error);
                    }
                });


    Using fluent-ffmpeg Generate Video thumb 

    
    var ffmpeg = require('fluent-ffmpeg');
     var image = random() + '.png';
     var imagepath = 'uploads/video_thumb/' + image;
     var pathToFile = path.join(__dirname, req.files[i].path),
     pathToSnapshot = path.join(__dirname, '/uploads/video_thumb/', image);
     
require('child_process').exec(('ffmpeg -ss 00:00:2 -i ' + pathToFile + ' -vframes 1 -q:v 2 ' + pathToSnapshot), function (err) {
                    //console.log(err);
                    //console.log('Saved the thumb to:', pathToSnapshot);
                });



Comments

Popular posts from this blog

Private Chat Using Node js and socket.io with encrypt and decrypt message and insert into mongo db

How To Migrate MVC 3 Application To MVC 5

Populate a drop-down in Vue.js and Asp.net Core from an ajax call