Image Processing
Alibaba Cloud OSS can process images on-the-fly. You can resize, crop, rotate, and add watermarks by passing the x-oss-process parameter.
Usage with getObject
You can download a processed version of an image directly:
$options = [
OssClient::OSS_FILE_DOWNLOAD => "resized.jpg",
OssClient::OSS_PROCESS => "image/resize,m_fixed,h_100,w_100",
];
$ossClient->getObject($bucket, "original.jpg", $options);
Common Operations
- Resize:
image/resize,w_200(Width to 200px) - Rotate:
image/rotate,90(Rotate 90 degrees) - Crop:
image/crop,w_100,h_100,x_10,y_10(Crop 100x100 starting at coordinates 10,10) - Watermark:
image/watermark,text_SGVsbG8=(Add text watermark) - Format Conversion:
image/format,png(Convert to PNG)
Generating a Processed URL
You can combine image processing with pre-signed URLs:
$options = [
OssClient::OSS_PROCESS => "image/resize,w_500"
];
$signedUrl = $ossClient->signUrl($bucket, "photo.jpg", 3600, "GET", $options);