图片高级压缩

最后更新时间:2021-05-27 15:35:30

    简介

    本文档提供关于图片高级压缩的 API 概览以及 SDK 示例代码。

    API 操作描述
    图片高级压缩 图片高级压缩可以更加高效地将图片转换为 TPG 或 HEIF 等高压缩比格式,有效降低图片传输链路及加载耗时,降低带宽及流量成本

    方法原型

    通过下载对象方法实现,用户只需要添加请求参数,请求参数格式如下,关于下载对象详细说明请参见 下载对象

    imageMogr2/format/<Format>
    参数 含义
    format 压缩格式,目标缩略图的图片格式为 TPG 或 HEIF。

    请求示例

    cos_pool_t *p = NULL;
    int is_cname = 0; 
    cos_status_t *s = NULL;
    cos_request_options_t *options = NULL;
    cos_string_t bucket;
    cos_string_t object;
    cos_string_t file;
    cos_table_t *resp_headers;
    cos_table_t *params = NULL;
    
    cos_pool_create(&p, NULL);
    options = cos_request_options_create(p);
    options->config = cos_config_create(options->pool);
    cos_str_set(&options->config->endpoint, TEST_COS_ENDPOINT);
    cos_str_set(&options->config->access_key_id, TEST_ACCESS_KEY_ID);
    cos_str_set(&options->config->access_key_secret, TEST_ACCESS_KEY_SECRET);
    cos_str_set(&options->config->appid, TEST_APPID);
    options->config->is_cname = is_cname;
    options->ctl = cos_http_controller_create(options->pool, 0);
    cos_str_set(&bucket, TEST_BUCKET_NAME);
    params = cos_table_make(p, 1);
    apr_table_addn(params, "imageMogr2/format/tpg", "");
    cos_str_set(&object, "test.jpg");
    cos_str_set(&file, "test.tpg");
    s = cos_get_object_to_file(options, &bucket, &object, NULL, params, &file, &resp_headers);
    log_status(s);
    if (!cos_status_is_ok(s)) {
      printf("cos_get_object_to_file fail, req_id:%s\n", s->req_id);
    }
    params = cos_table_make(p, 1);
    apr_table_addn(params, "imageMogr2/format/heif", "");
    cos_str_set(&file, "test.heif");
    s = cos_get_object_to_file(options, &bucket, &object, NULL, params, &file, &resp_headers);
    log_status(s);
    if (!cos_status_is_ok(s)) {
      printf("cos_get_object_to_file fail, req_id:%s\n", s->req_id);
    }