首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用节点缩略图从图像生成缩略图

使用节点缩略图从图像生成缩略图
EN

Stack Overflow用户
提问于 2018-01-28 21:53:13
回答 1查看 3K关注 0票数 0

我试图从图像生成一个缩略图使用节点-缩略图,缩略图被上传到我的容器在蔚蓝存储,但它看起来像原始文件,而不是缩略图。这是我的代码,首先我上传原始图像,然后读取它并从中生成缩略图,然后将缩略图上传到容器中。我做错了什么?我在网上找不到很多关于如何做到这一点的资源,请帮助!

代码语言:javascript
复制
app.post('/upload', function(req, res) {
if (!req.files)
  return res.status(400).send('No files were uploaded.');

// The name of the input field (i.e. "sampleFile") is used to retrieve the uploaded file
let sampleFile = req.files.sampleFile;
let name = sampleFile.name;
let data = sampleFile.data;
//var options = { contentSettings: { contentType: 'image/jpeg' } }

blobSvc.createBlockBlobFromText('test-container', name, data, function(error, result, response){
    if (error){
        return res.status(500).send(error);
    } else {
        console.log('Uploaded to container');
    }


    var info = blobSvc.getBlobToLocalFile ("test-container", name, name,
        function (error, blockBlob, response) {
            thumb({
                source: name, // could be a filename: dest/path/image.jpg
                destination: './',
                concurrency: 4,
                width: 100
              }, function(files, err){
                if (err) throw err;
                console.log("resized");
                //Delete the downloaded BIG one


                //Upload the thumbnail
                blobSvc.createBlockBlobFromLocalFile("test-container", files[0].dstPath, files[0].dstPath,
                function (error, blockBlob, response) {
                    if (!error) {
                        console.log("thumbnail uploaded: " + name);

                    } else{
                        console.log(error);
                    }

                });
            });
        });

});     
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-29 08:52:56

这实际上不是一个Azure存储问题,它更像是一个node-thumbnail问题。

使用Jimp怎么样?

代码语言:javascript
复制
var azure = require('azure-storage');
var Jimp = require("jimp");
var path = require('path');

// ...

var info = blobSvc.getBlobToLocalFile("test-container", name, name, function(error, blockBlob, response) {

    if (!error) {

        var dstName = path.parse(name).name + "_thumb" + path.parse(name).ext;

        Jimp.read(name, function(err, image) {

            if (err) throw err;
            image.resize(100, Jimp.AUTO)             // resize
                .quality(60)                         // set JPEG quality
                .write(dstName, function(err, ret) { // save

                    //Upload the thumbnail
                    blobSvc.createBlockBlobFromLocalFile("test-container", dstName, dstName, function(error, blockBlob, response) {
                        if (!error) {
                            console.log("thumbnail uploaded: " + dstName);
                        } else {
                            console.log(error);
                        }

                    });
                });
        });
    }
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48491738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档