API | Description |
QR code recognition | Recognizes the location and content of valid QR codes in an image, outputs the text information (URL or text) contained in the QR codes, and pixelates the recognized QR codes. |
QR code generation | Generates QR codes or barcodes based on the specified text information (URL or text). |
func (s *CIService) GetQRcode(ctx context.Context, name string, cover int, opt *ObjectGetOptions, id ...string) (*GetQRcodeResult, *Response, error)
opt := &cos.ObjectPutOptions{nil,&cos.ObjectPutHeaderOptions{XOptionHeader: &http.Header{},},}pic := &cos.PicOperations{IsPicInfo: 1,Rules: []cos.PicOperationsRules{{FileId: "format.jpg",Rule: "QRcode/cover/1",},},}opt.XOptionHeader.Add("Pic-Operations", cos.EncodePicOperations(pic))name := "test.jpg"filepath := "./QRcode.jpg"res, _, err := c.CI.PutFromFile(context.Background(), name, filepath, opt)
name := "test.jpg"res, _, err := c.CI.GetQRcode(context.Background(), name, 1, nil)
Parameter | Description | Type | Required |
cover | Pixelates the recognized QR code. Valid values: 0 (no), 1 (yes). Default value: 0 . | int | Yes |
type GetQRcodeResult struct {CodeStatus intQRcodeInfo *QRcodeInfoResultImage string}type QRcodeInfo struct {CodeUrl stringCodeLocation *CodeLocation}type CodeLocation struct {Point []string}
Parameter | Description | Type |
CodeStatus | Whether QR codes are recognized. 0 : No; 1 : Yes. | int |
QRcodeInfo | Recognized QR code. There may be multiple ones. | Struct |
ResultImage | Base64-encoded image data, which is returned if the request parameter cover is 1. | string |
CodeUrl | QR code content. Content may not be recognized. | string |
CodeLocation | Location coordinates of the QR code recognized in the image. | Struct |
Point | QR code coordinates (X,Y). | Array |
func (s *CIService) GenerateQRcode(ctx context.Context, opt *GenerateQRcodeOptions) (*GenerateQRcodeResult, *Response, error)func (s *CIService) GenerateQRcodeToFile(ctx context.Context, filePath string, opt *GenerateQRcodeOptions) (*GenerateQRcodeResult, *Response, error)
opt := &cos.GenerateQRcodeOptions{QRcodeContent: "<https://www.example.com>"Mode: 0,Width: 200,}// Case 1. Generate a QR coderes, _, err := c.CI.GenerateQRcode(context.Background(), opt)// Case 2. Generate a QR code and save it as a filefilepath := "example.jpg"res, _, err := c.CI.GenerateQRcodeToFile(context.Background(), filepath, opt)
type GenerateQRcodeOptions struct {QRcodeContent stringMode intWidth int}
Parameter | Description | Type |
QRcodeContent | Recognizable QR code text information | string |
Mode | Type of the QR code to be generated. Valid values: 0 (QR code), 1 (barcode). Default value: 0 . | int |
Width | Width of the QR code or barcode to be generated. The height will be compressed proportionally. | int |
type GenerateQRcodeResult struct {ResultImage string}
Parameter | Description | Type |
ResultImage | Base64-encoded QR code image data | string |
Was this page helpful?