【发布时间】:2018-03-05 10:33:43
【问题描述】:
我按照 firecasts 中的 Firebase 功能教程:https://www.youtube.com/watch?v=pDLpEn3PbmE&t=338s 在上传图片时使用 firebase 创建缩略图。
这一切都很好,但是当我上传用 iPhone 拍摄的图像时,它会旋转(垂直图像水平保存)。所以我对此做了一些研究,发现了 ImageMagick (http://magick.imagemagick.org/script/command-line-options.php#auto-orient) 中的 -auto-orient 参数
但我不确定如何将此参数添加到 spawn 函数以考虑此参数
没有-auto-orient的我的工作代码(只是其中相关的部分)
...
return bucket.file(filePath).download({
destination: tempFilePath
})
.then(() => {
console.log('Image downloaded locally to', tempFilePath);
return spawn('convert', [tempFilePath, '-thumbnail', '200x200>', tempFilePath]);
})
.then(() => {
console.log('Thumbnail created!');
const thumbFilePath = filePath.replace(/(\/)?([^\/]*)$/, '$1thumb_$2');
console.log(`thumbFilePath: ${thumbFilePath}`);
return bucket.upload(tempFilePath, {
destination: thumbFilePath
});
})
...
我尝试使用-auto-orient 参数的代码
...
return bucket.file(filePath).download({
destination: tempFilePath
})
.then(() => {
console.log('Image downloaded locally to', tempFilePath);
return spawn('convert', ['-auto-orient', tempFilePath, '-thumbnail', '200x200>', tempFilePath]);
})
.then(() => {
console.log('Thumbnail created!');
const thumbFilePath = filePath.replace(/(\/)?([^\/]*)$/, '$1thumb_$2');
console.log(`thumbFilePath: ${thumbFilePath}`);
return bucket.upload(tempFilePath, {
destination: thumbFilePath
});
})
...
但是当我将它部署到 firebase 并尝试上传图片时,我收到以下错误消息,但它并没有提供很多关于它为什么不工作的信息
Function execution took 6227 ms, finished with status: 'connection error'
有什么想法吗?
【问题讨论】:
-
你解决过这个问题吗?我遇到了同样的错误。
-
不,还没有时间调查这个问题。
-
我昨晚解决了这个问题。当您有时间调查时,请在下面查看我的答案!
标签: javascript firebase imagemagick google-cloud-functions imagemagick-convert