问题描述
我正在编写执行以下操作的Firebase云功能:
下面是代码。它可以自动旋转,没有任何问题。但是,转换并保存的图像仍是基准图像,即它们会逐行显示,这不利于现代Web环境中的用户体验。
关于出什么问题了吗?我怀疑这可能是简单的事情,例如在使用ImageMagick命令时出现语法错误,但想寻求建议。
exports.convertimage = functions.storage.object().onFinalize(async (object) => {
const filePath = object.name;
const bucketName = object.bucket;
const Metadata = object.Metadata;
const tempLocalFile = path.join(os.tmpdir(),filePath);
const tempLocalDir = path.dirname(tempLocalFile);
const bucket = storage.bucket(bucketName);
const spawn = require('child-process-promise').spawn;
if (!object.contentType.startsWith('image/')) {
console.log('This is not an image.')
return null;
}
if (Metadata.autoOrient) {
console.log('This is already rotated');
return null;
}
return mkdirp(tempLocalDir).then(() => {
// Download file from bucket.
return bucket.file(filePath).download({destination: tempLocalFile})
}).then(() => {
// Convert the image using ImageMagick. I guess this is where it went wrong??
return spawn('convert',[tempLocalFile,'-auto-orient','-quality','80','-interlace','Plane',tempLocalFile])
}).then(() => {
Metadata.autoOrient = true
return bucket.upload(tempLocalFile,{
destination: filePath,Metadata: {Metadata: Metadata}
})
}).then(() => {
// Once the image has been converted delete the local files to free up disk space.
fs.unlinkSync(tempLocalFile)
console.log('Auto rotation,compression and PJPEG convsersion successful for the original file')
})
})
非常感谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)