我是否可以访问Google Cloud功能中的GraphicsMagicks或ImageMagicks?

kra*_*ene 3 imagemagick graphicsmagick google-cloud-platform google-cloud-functions

我想创建一个Google Cloud功能,可以正确设置上传文件的内容类型.我知道如何使用GraphicsMagick或ImageMagick,但我不确定Google Cloud Function是否具有这些本机库.我如何知道他们是否有这些或未能如何安装它们?

Fra*_*len 9

Google Cloud Functions在安装了ImageMagick的容器中运行.不知何故,Firebase文档似乎有最好的文档.从那里:

云功能提供了一个称为ImageMagick可以对图形图像文件进行操作的图像处理程序.以下是如何为上载的图像文件创建缩略图图像的示例:

    // Download file from bucket.
    const bucket = gcs.bucket(fileBucket);
    const tempFilePath = `/tmp/${fileName}`;
    return bucket.file(filePath).download({
      destination: tempFilePath
    }).then(() => {
      console.log('Image downloaded locally to', tempFilePath);
      // Generate a thumbnail using ImageMagick.
      return exec(`convert "${tempFilePath}" -thumbnail '200x200>' "${tempFilePath}"`).then(() => {
        console.log('Thumbnail created at', tempFilePath);
        // We add a 'thumb_' prefix to thumbnails file name. That's where we'll upload the thumbnail.
        const thumbFilePath = filePath.replace(/(\/)?([^\/]*)$/, `$1thumb_$2`);
        // Uploading the thumbnail.
        return bucket.upload(tempFilePath, {
          destination: thumbFilePath
        });
      });
    });
Run Code Online (Sandbox Code Playgroud)

此代码执行ImageMagick命令行程序转换,为保存在临时目录中的映像创建200x200缩略图,然后将其上载回云存储.

另请参阅Firebase函数 - 示例repo以获取如何使用它的示例:https://github.com/firebase/functions-samples/tree/master/generate-thumbnail

  • 您可以通过将其放在功能所在的同一文件夹中来安装其他二进制文件.[Jason](https://cloudnext.withgoogle.com/schedule#target=building-serverless-applications-with-google-cloud-functions-c30bf9bd-c0ca-4256-b167-34a656b76703)或[Bret](https: //www.youtube.com/watch?v=BybYim0HRmY)在最近的一次演讲中解释过. (2认同)
  • 同样的:我必须从我们的一个云人那里学到这一点.我刚刚意识到这不仅仅是在一个视频中,而且还在这里:http://stackoverflow.com/questions/42773497/can-you-call-out-to-ffmpeg-in-a-firebase-cloud-function (2认同)