You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Image Processing
Basic Image Processing (Go SDK)
Copy page
Download PDF
Basic Image Processing (Go SDK)
TOS supports processing of stored images, including image resizing, image cropping, image watermarking, format conversion, and other image processing operations. This article introduces how to perform basic image processing using the TOS Go SDK.​
Precautions​
  • The original image format supports only JPG, PNG, BMP, GIF, WEBP, and TIFF.​
  • The size of the original image must not exceed 20 MB.​
  • The original image width and height must not exceed 30,000 px, and the total number of pixels must not exceed 250 million px. For rotation operations, the original image width and height must not exceed 4,096 px.​
  • Neither the width nor the height of the scaled image may exceed 16,384 px, and the total number of pixels must not exceed 16,777,216 px.​
Sample Code​
The following code demonstrates how to set the image height to 100px, convert the image format to JPG, name the image temp.jpg, and download it to your computer.​
​
package main​
​
import (​
"context"​
"fmt"​
"github.com/volcengine/ve-tos-golang-sdk/v2/tos"​
)​
​
func checkErr(err error) {​
if err != nil {​
if serverErr, ok := err.(*tos.TosServerError); ok {​
fmt.Println("Error:", serverErr.Error())​
fmt.Println("Request ID:", serverErr.RequestID)​
fmt.Println("Response Status Code:", serverErr.StatusCode)​
fmt.Println("Response Header:", serverErr.Header)​
fmt.Println("Response Err Code:", serverErr.Code)​
fmt.Println("Response Err Msg:", serverErr.Message)​
} else {​
fmt.Println("Error:", err)​
}​
panic(err)​
}​
}​
​
func main() {​
var (​
accessKey = os.Getenv("TOS_ACCESS_KEY")​
secretKey = os.Getenv("TOS_SECRET_KEY")​
​
endpoint = "https://tos-cn-beijing.volces.com"​
region = "cn-beijing"​
​
bucketName = "*** Provide your bucket name ***"​
​
​
imageKey = "image.png"​
ctx = context.Background()​
fileName = "temp.jpg"​
)​
​
client, err := tos.NewClientV2(endpoint, tos.WithRegion(region), tos.WithCredentials(tos.NewStaticCredentials(accessKey, secretKey)))​
checkErr(err)​
​
​
style := "image/resize,h_100/format,jpg" ​
out, err := client.GetObjectToFile(ctx, &tos.GetObjectToFileInput{GetObjectV2Input: tos.GetObjectV2Input{Bucket: bucketName, Key: imageKey, Process: style}, FilePath: fileName})​
checkErr(err)​
fmt.Println("ContentType:", out.ContentType)​
​
}​
​
Relevant Documentation​
For a detailed introduction to image processing, please refer to Image Processing Overview.​
Last updated: 2025.09.19 17:30:22