首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用google云函数调用imagemagick 'identify‘

使用google云函数调用imagemagick 'identify‘
EN

Stack Overflow用户
提问于 2019-05-08 01:56:40
回答 1查看 76关注 0票数 0

我正在尝试在我的Google Cloud函数中使用imagemagick。上传文件到Google云存储存储桶即可触发该函数。我有更宏伟的计划,但试图一步一步地实现。以identify开头。

代码语言:javascript
复制
    // imagemagick_setup
    const gm = require('gm').subClass({imageMagick: true});
    const path = require('path');
    const {Storage} = require('@google-cloud/storage');
    const storage = new Storage();

    exports.processListingImage = (event, context) => {
        const object = event.data || event; // Node 6: event.data === Node 8+: event
        const filename = object.name;
        console.log("Filename: ", filename);

        const fullFileObject = storage.bucket(object.bucket).file(object.name);

        console.log("Calling resize function");
        let resizePromise = resizeImage( fullFileObject );

        <more stuff>
    };


    function resizeImage( file, sizes ) {
        const tempLocalPath = `/tmp/${path.parse(file.name).base}`;

        return file
            .download({destination: tempLocalPath})
            .catch(err => {
                console.error('Failed to download file.', err);
                return Promise.reject(err);
            })
            .then( () => {
                // file now downloaded, get it's metadata
                return new Promise((resolve, reject) => {
                    gm( tempLocalPath )
                        .identify( (err, result) => {
                            if (err)
                            {
                                console.log("Error reading metadata: ", err);
                            }
                            else
                            {
                                console.log("Well, there seems to be metadata: ", result);
                            }
                        });
                });
          });
    } // end resizeImage()

本地文件路径为:/tmp/andy-test.raw。但是当identify函数运行时,我得到一个错误:

代码语言:javascript
复制
identify-im6.q16: unable to open image `/tmp/magick-12MgKrSna0qp9U.ppm': No such file or directory @ error/blob.c/OpenBlob/2701.

为什么identify要查找的文件与我告诉它要查找的文件不同?最终,我将调整镜像的大小,并将其写回云存储,但我想让identify先运行。

EN

回答 1

Stack Overflow用户

发布于 2019-05-08 04:17:18

Mark给出了正确的答案--如果我上传了一个jpg文件,它就能工作。进入下一个挑战。

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

https://stackoverflow.com/questions/56028128

复制
相关文章

相似问题

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