我想使用cloudinary为我想在node.js中上传的图像添加水印,这是一个示例; const conversionString =
text:arial_20_bold:Location-${location}, Date-${new Date().toLocaleDateString()}, Time-${new Date().toLocaleTimeString()}
;
const result = await cloudinary.uploader.upload(studentImage.tempFilePath, {
folder: 'Image-Upload',
overwrite: true,
tags: ['location', 'time', 'date'],
transformation: [
{ width: 500, height: 500, crop: 'fill' }, // Resize the image
{ overlay: transformationString, gravity: 'south_east', color: 'white', opacity: 80, width: 400 }
]
})
但它显示此错误“无效的转换组件 - Date-4”
那是因为您使用逗号分隔链式转换,而 Cloudinary 会将其解释为不同的转换。
或者您可以逃避逗号,请阅读以下内容:https://support.cloudinary.com/hc/en-us/articles/202521512-How-to-add-a-special-characters-in-text-overlays
或者您可以删除
Date
和 Time
之前的逗号,如下所示:
text:arial_20_bold:Location-${location} Date-${new Date().toLocaleDateString()} Time-${new Date().toLocaleTimeString()}