我有一个网站,用户可以在其中上传图片。
我希望所有已经上传的图像+任何新上传的图像的质量都相同。
有没有一种方法可以轻松地编辑已经上传的图像,而无需让用户重新上传各自的图像?
谢谢
答案 0 :(得分:0)
Cloudinary的美丽之处在于能够上传原始文档,然后进行转换。通常,建议看起来是:
quality
参数设置为auto
(URL中的 q_auto ),以自动调整图像的质量,以在质量和尺寸之间取得适当的平衡。fetch_format
参数设置为auto
(URL中的 f_auto ),以根据浏览器自动选择最佳格式。示例:https://res.cloudinary.com/demo/image/upload/q_auto,f_auto,w_500/bike.jpg
来源(以及更多信息):https://cloudinary.com/documentation/image_optimization)。
但是,如果您需要重新上传内容并保留相同的public_id
,最简单的解决方案是使用其API。我建议执行以下操作:
resource_type
,并且如果使用的话,还应将参数tags
设置为true
,将context
设置为true
。 注意:管理API受速率限制,因此请检查与计划here关联的使用限制。将它们存储在数组中以备后用。响应应包括public_id
,url
,tags
,context
等... 遍历先前的数组,并使用Upload API's upload method使用与先前检索的相同参数(public_id
,url
,tags
, context
等。例如
current_assets = [...]
for (asset in current_assets) {
result = cloudinary.v2.uploader.upload(
asset['url'],
{ public_id: asset['public_id'], tags: asset['tags'], context: assets['context']
// include any incoming transformations to apply to the asset during upload
},
(err, res) => {
if (err) console.log(err);
console.log(res);
})
}