You need to enable JavaScript to run this app.
导航

基础图片处理(iOS SDK)

最近更新时间2024.02.04 18:31:09

首次发布时间2023.11.03 16:08:03

TOS 支持对存储的图片进行处理,包括图片缩放、图片裁剪、图片水印、格式转换等图片处理操作。

注意事项

  • 原图格式仅支持 JPG、PNG、BMP、GIF、WEBP 和 TIFF。
  • 原图大小不能超过 20MB。
  • 原图宽、高不能超过 30000 px,总像素不能超过 2.5 亿 px(旋转操作的原图宽、高不能超过 4096 px)。
  • 缩放后的图片宽、高不能超过 16384 px,总像素不能超过 16777216 px。

示例代码

以下代码展示将图片缩放为高度 100px,然后将处理后的图片保存到本地。

// 从STS服务获取的临时访问密钥和安全令牌(AccessKey、SecretKey、SecurityToken)
TOSCredential *credential = [[TOSCredential alloc] initWithAccessKey:@"accesskey" secretKey:@"secretkey" securityToken:@"securityToken"];
TOSEndpoint *tosEndpoint = [[TOSEndpoint alloc] initWithURLString:@"endpoint" withRegion:@"region"];
TOSClientConfiguration *config = [[TOSClientConfiguration alloc] initWithEndpoint:tosEndpoint credential:credential];
TOSClient *client = [[TOSClient alloc] initWithConfiguration:config];

TOSGetObjectToFileInput *get = [TOSGetObjectToFileInput new];
get.tosBucket = @"bucket-name";
get.tosKey = @"image-name";
get.tosFilePath = @"your_local_file_path";
get.tosProcess = @"image/resize,h_100";
TOSTask *task = [client getObjectToFile:get];
[task continueWithBlock:^id _Nullable(TOSTask * _Nonnull t) {
    if (!task.error) {
        NSLog(@"Get object to file success.");
    } else {
        NSLog(@"Get object to file failed, error: %@" ,task.error);
    }
    return nil;
}];

相关文档

关于图片处理的详细介绍,请参见图片处理概述