kra*_*ene 3 imagemagick graphicsmagick google-cloud-platform google-cloud-functions
我想创建一个Google Cloud功能,可以正确设置上传文件的内容类型.我知道如何使用GraphicsMagick或ImageMagick,但我不确定Google Cloud Function是否具有这些本机库.我如何知道他们是否有这些或未能如何安装它们?
Google Cloud Functions在安装了ImageMagick的容器中运行.不知何故,Firebase文档似乎有最好的文档.从那里:
云功能提供了一个称为
ImageMagick可以对图形图像文件进行操作的图像处理程序.以下是如何为上载的图像文件创建缩略图图像的示例:Run Code Online (Sandbox Code Playgroud)// 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 }); }); });此代码执行ImageMagick命令行程序转换,为保存在临时目录中的映像创建200x200缩略图,然后将其上载回云存储.
另请参阅Firebase函数 - 示例repo以获取如何使用它的示例:https://github.com/firebase/functions-samples/tree/master/generate-thumbnail
| 归档时间: |
|
| 查看次数: |
2581 次 |
| 最近记录: |