【问题标题】:Can you edit the quality of user uploaded images on Cloudinary?您可以在 Cloudinary 上编辑用户上传图像的质量吗?
【发布时间】:2020-02-15 15:38:54
【问题描述】:

我有一个用户上传图片的网站。

我希望所有已上传图片 + 任何新上传图片的质量都相同。

有没有一种方法可以轻松编辑已上传的图片,而无需让用户重新上传各自的图片?

谢谢

【问题讨论】:

    标签: node.js express cloudinary


    【解决方案1】:

    Cloudinary 的美妙之处在于能够上传原件,然后进行转换。通常,建议看起来是:

    1. quality 参数设置为auto(URL 中的q_auto)以自动调整图像质量以在质量和大小之间取得适当的平衡
    2. fetch_format 参数设置为auto(URL 中的f_auto)以根据浏览器自动选择最佳格式。
    3. 将高度和宽度调整为页面上呈现的必要尺寸。

    示例:https://res.cloudinary.com/demo/image/upload/q_auto,f_auto,w_500/bike.jpg

    来源(以及更多信息)https://cloudinary.com/documentation/image_optimization)。

    但如果您需要重新上传内容并保持相同的public_id,最简单的解决方案是使用他们的 API。我建议执行以下操作:

    1. 使用Admin APIs get resources call 检索需要重新上传的资产。我建议通过resource_type 分解这些参数,如果使用,我还将包括参数tags 设置为truecontext 设置为true注意 Admin API 有速率限制,因此请检查与您的计划相关的使用限制here。将这些存储在一个数组中以备后用。响应应包括public_idurltagscontext 等...
    2. 遍历前一个数组并使用Upload API's upload method 使用之前检索到的相同参数(public_idurltagscontext 等重新上传内容。例如

      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);
          })
      }
      

    来源https://cloudinary.com/documentation/upload_images?query=incoming&c_query=Incoming%20transformations#incoming_transformations

    【讨论】:

      猜你喜欢
      • 2021-04-04
      • 1970-01-01
      • 2016-08-24
      • 1970-01-01
      • 2020-12-22
      • 2019-04-21
      • 2012-10-11
      • 2019-01-24
      • 2016-11-12
      相关资源
      最近更新 更多