Service | Feature | Description |
Image Processing-Basic Services | Proportional scaling, scaling image to target width and height, and more | |
| Cut (regular cropping), crop (scaling and cropping), iradius (inscribed circle cropping), and scrop (smart cropping) | |
| Adaptive rotation and common rotation | |
| Format conversion, GIF optimization, and progressive display | |
| Changes the quality of images in JPG and WEBP formats | |
| Blurs images | |
| Adjusts image brightness | |
| Adjusts contrast | |
| Sharpens images | |
| Watermarking | |
| Obtaining image information | |
| Includes EXIF data | |
| Performs quick format conversion, scaling, and cropping to generate thumbnails | |
| Performs multiple types of processing on images in a sequence |
<?phprequire dirname(__FILE__) . '/../vendor/autoload.php';$secretId = "SECRETID"; //Replace it with the actual SecretId, which can be viewed and managed at https://console.tencentcloud.com/cam/capi$secretKey = "SECRETKEY"; //Replace it with the actual SecretKey, which can be viewed and managed at https://console.tencentcloud.com/cam/capi$region = "ap-beijing"; //Replace it with the actual region, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket$cosClient = new Qcloud\\Cos\\Client(array('region' => $region,'schema' => 'https', // Protocol header, which is http by default'credentials'=> array('secretId' => $secretId ,'secretKey' => $secretKey)));try {$imageMogrTemplate = new Qcloud\\Cos\\ImageParamTemplate\\ImageMogrTemplate(); //Create an instance of the basic image processing parameter template$imageMogrTemplate->thumbnailByScale(50); //Scale an image to 50% of its original width and height$result = $cosClient->getObject(array('Bucket' => 'examplebucket-1250000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket'Key' => 'exampleobject','ImageHandleParam' => $imageMogrTemplate->queryString(), //Generate basic image processing parameters));// Request succeededprint_r($result);} catch (\\Exception $e) {// Request failedecho($e);}
Parameter | Type | Description | Required |
Bucket | String | Bucket name in the format of BucketName-APPID | Yes |
Key | String | Uniquely identifies an object in a bucket. For example, if the object access endpoint is examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg , its object key is doc/pic.jpg . | Yes |
ImageHandleParam | String | CI image processing parameters, such as imageMogr2/thumbnail/!50p | Yes |
Guzzle\\Service\\Resource\\Model Object([structure:protected] =>[data:protected] => Array([Body] =>[RequestId] => NWQwOGRkNDdfMjJiMjU4NjRfNzVjXzEwNmVjY2M=[ContentLength] => 100[CacheControl] => max-age=2592000[ContentType] => image/jpeg[Key] => exampleobject[Bucket] => examplebucket-1250000000[Location] => examplebucket-1250000000.cos.ap-beijing.myqcloud.com/exampleobject))
Parameter | Type | Description | Parent Node |
Body | File/String | Downloaded content | None |
RequestId | String | Request ID | None |
CacheControl | String | Cache policy. Sets Cache-Control . | None |
ContentType | String | Content type. Sets Content-Type | None |
ContentLength | Int | Length of the response body | None |
Key | String | Object key | None |
Bucket | String | Bucket name in the format of BucketName-APPID | None |
Location | String | Address of the requested resource | None |
$imageMogrTemplate->thumbnailByScale(50); //Scale an image to 50% of its original width and height$imageMogrTemplate->thumbnailByWidthScale(50); //Scale an image to 50% of its original width while keeping the height unchanged$imageMogrTemplate->thumbnailByHeightScale(50); //Scale an image to 50% of its original height while keeping the width unchanged
$imageMogrTemplate->thumbnailByWidth(50); //Specify the target image width as 50, with the height proportionally scaled down$imageMogrTemplate->thumbnailByHeight(50); //Specify the target image height as 50, with the width proportionally scaled down$imageMogrTemplate->thumbnailByMaxWH(50, 50); //Specify the maximum width and height of a thumbnail as 50 and 50 respectively for proportional scaling$imageMogrTemplate->thumbnailByMinWH(50, 50);//Specify the minimum width and height of a thumbnail as 50 and 50 respectively for proportional scaling$imageMogrTemplate->thumbnailByWH(50, 50); //Force image scaling with the specified width (50) and height (50), which may cause deformation of the target image
$imageMogrTemplate->thumbnailByPixel(1000); //Proportionally scale an image so that the total number of its pixels does not exceed 1,000
$imageMogrTemplate->cut(100, 300, 30, 30); //Perform cropping based on the specified target width, height, and horizontal offset and vertical offset relative to the upper-left vertex of the output image
$imageMogrTemplate->cropByWidth(100); //Perform scaling and cropping based on the specified target width$imageMogrTemplate->cropByWidth(100, 'center'); //Perform scaling and cropping based on the specified target width and operation start point$imageMogrTemplate->cropByHeight(100); //Perform scaling and cropping based on the specified target height$imageMogrTemplate->cropByHeight(100, 'center'); //Perform scaling and cropping based on the specified target height and operation start point$imageMogrTemplate->cropByWH(100, 100); //Perform scaling and cropping based on the specified target width and height$imageMogrTemplate->cropByWH(100, 100, 'center'); //Perform scaling and cropping based on the specified target width and height, as well as the operation start point
radius
specifies the radius of the inscribed circle. The value of radius
should be an integer greater than 0 but smaller than half the length of the input image’s shorter side. The center of the inscribed circle is the center of the input image. This operation is not available for GIF images.$imageMogrTemplate->iradius(100); //Specify radius as 100 in this example
radius
specifies the radius of the rounded corners of an image. The value of radius
should be an integer greater than 0 but smaller than half the length of the input image’s shorter side. The two sides of the input image are the tangent lines of the rounded corner. This operation is not available for GIF images.$imageMogrTemplate->rradius(1000); // Specify radius as 100 in this example
Width
and Height
respectively.$imageMogrTemplate->scrop(100, 100); //Scale and crop an image to 100x100 based on the face position in the image in this example
$imageMogrTemplate->rotate(45); //This example rotates an image by 45 degrees clockwise
$imageMogrTemplate->autoOrient();
$imageMogrTemplate->format('png'); //Convert an image to the PNG format
FrameNumber
:FrameNumber
).$imageMogrTemplate->gifOptimization(50); //Compress the image to 50 frames
Mode
parameter is used to specify whether to enable or disable the progressive mode. This parameter takes effect only when the output image is in JPG format. Otherwise, this parameter will be ignored. The parameter value can be 0 (disable the progressive mode) or 1 (enable the progressive mode). The default value is 0.$imageMogrTemplate->jpegInterlaceMode(1); //Enable the progressive mode
$imageMogrTemplate->quality(90, 1); //Use the specified quality 90 by force
rquality
is set to 80
, the quality of the output image is 64 (that is, 80 x 80%).$imageMogrTemplate->relativelyQuality(80);
lquality
is set to 80, the quality of the output image is 85.lquality
is set to 80, the quality of the output image will be improved to 80.$imageMogrTemplate->lowestQuality(90);
$imageMogrTemplate->blur(20, 20); //The blur radius is 20 and the standard deviation of normal distribution is 20 in this example
//Value < 0: reduce the image brightness//Value = 0: do not adjust the image brightness//Value > 0: increase the image brightness$imageMogrTemplate->bright(50); //Increase the image brightness by 50
//Value < 0: reduce the image contrast//Value = 0: do not adjust the image contrast//Value > 0: increase the image contrast$imageMogrTemplate->contrast(50); //Increase the image contrast by 50
$imageMogrTemplate->sharpen(70); //Sharpen an image with the sharpening value of 70
examplebucket-1250000000.file.myqcloud.com/shuiyin_2.png
is unsupported) and be accessible. If the image watermark is set to private-read, it must carry a signature.http://
. Note that "http://" cannot be omitted or changed to "https://". For example, examplebucket-1250000000.cos.ap-shanghai.myqcloud.com/shuiyin_2.png
and https://examplebucket-1250000000.cos.ap-shanghai.myqcloud.com/shuiyin_2.png
are invalid watermark URLs.<?phprequire dirname(__FILE__) . '/../vendor/autoload.php';$secretId = "SECRETID"; //Replace it with the actual SecretId, which can be viewed and managed at https://console.tencentcloud.com/cam/capi$secretKey = "SECRETKEY"; //Replace it with the actual SecretKey, which can be viewed and managed at https://console.tencentcloud.com/cam/capi$region = "ap-beijing"; //Replace it with the actual region, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket$cosClient = new Qcloud\\Cos\\Client(array('region' => $region,'schema' => 'https', // Protocol header, which is http by default'credentials'=> array('secretId' => $secretId ,'secretKey' => $secretKey)));try {$imageWatermarkTemplate = new Qcloud\\Cos\\ImageParamTemplate\\ImageWatermarkTemplate(); //Create an image watermark parameter template instance$imageWatermarkTemplate->setImage("imageurl"); //Set the watermark image address$imageWatermarkTemplate->setGravity('center'); //Set the position of the watermark in the 3x3 grid position diagram$imageWatermarkTemplate->setDx(10); //Set the horizontal offset$imageWatermarkTemplate->setDy(10); //Set the vertical offset$imageWatermarkTemplate->setBlogo(1); //Set the adaptation mode for an image watermark that is larger than the input image. Valid values: 1 (scale the image watermark to the size of the input image), 2 (crop the image watermark to the size of the input image)$imageWatermarkTemplate->setScatype(1); //Set the scaling mode for the image watermark (relative to the input image). Valid values: 1 (scale by width), 2 (scale by height), 3 (scale by area)$imageWatermarkTemplate->setSpcent(100); //Set the scale ratio of the image watermark (relative to the input image), in permillage, to 100/1000. Value range: [1,1000]. By default, the image watermark is not scaled.$result = $cosClient->getObject(array('Bucket' => 'examplebucket-1250000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket'Key' => 'exampleobject','ImageHandleParam' => $imageWatermarkTemplate->queryString(), //Generate image watermark parameters));// Request succeededprint_r($result);} catch (\\Exception $e) {// Request failedecho($e);}
<?phprequire dirname(__FILE__) . '/../vendor/autoload.php';$secretId = "SECRETID"; //Replace it with the actual SecretId, which can be viewed and managed at https://console.tencentcloud.com/cam/capi$secretKey = "SECRETKEY"; //Replace it with the actual SecretKey, which can be viewed and managed at https://console.tencentcloud.com/cam/capi$region = "ap-beijing"; //Replace it with the actual region, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket$cosClient = new Qcloud\\Cos\\Client(array('region' => $region,'schema' => 'https', // Protocol header, which is http by default'credentials'=> array('secretId' => $secretId ,'secretKey' => $secretKey)));try {$textWatermarkTemplate = new Qcloud\\Cos\\ImageParamTemplate\\TextWatermarkTemplate(); //Create a text watermark parameter template instance$textWatermarkTemplate->setText("test"); //Set the watermark text$textWatermarkTemplate->setFont("tahoma.ttf"); //Set the font of the watermark text. Default value: `tahoma.ttf`$textWatermarkTemplate->setFontsize(30); //Set the watermark text font size, in pounds. Default value: `13`$textWatermarkTemplate->setFill("#3D3D3D"); //Set the font color. The value must be in hexadecimal RGB format, for example, `#FF0000`. Default value: `#3D3D3D` (gray)$textWatermarkTemplate->setDissolve(90); //Set the text opacity. Value range: 1−100. Default value: `90` (meaning 90% opacity)$textWatermarkTemplate->setGravity('center'); //Set the position of the text watermark in the 3x3 grid position diagram. Default value: `southeast`$textWatermarkTemplate->setDx(10); //Set the horizontal offset in pixels. Default value: `0`$textWatermarkTemplate->setDy(10); //Set the vertical offset in pixels. Default value: `0`$textWatermarkTemplate->setBatch(1); //Set whether to tile the text watermark. If this parameter is set to `1`, the text watermark will be tiled across the input image.$textWatermarkTemplate->setDegree(45); //Set the angle to rotate the text watermark. Value range: 0−360. Default value: `0`$result = $cosClient->getObject(array('Bucket' => 'examplebucket-1250000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket'Key' => 'exampleobject','ImageHandleParam' => $textWatermarkTemplate->queryString(), //Generate text watermark parameters));// Request succeededprint_r($result);} catch (\\Exception $e) {// Request failedecho($e);}
<?phprequire dirname(__FILE__) . '/../vendor/autoload.php';$secretId = "SECRETID"; //Replace it with the actual SecretId, which can be viewed and managed at https://console.tencentcloud.com/cam/capi$secretKey = "SECRETKEY"; //Replace it with the actual SecretKey, which can be viewed and managed at https://console.tencentcloud.com/cam/capi$region = "ap-beijing"; //Replace it with the actual region, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket$cosClient = new Qcloud\\Cos\\Client(array('region' => $region,'schema' => 'https', // Protocol header, which is http by default'credentials'=> array('secretId' => $secretId ,'secretKey' => $secretKey)));try {$result = $cosClient->ImageInfo(array('Bucket' => 'examplebucket-1250000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket'Key' => 'exampleobject',));// Request succeededprint_r($result);} catch (\\Exception $e) {// Request failedecho($e);}
Parameter | Type | Description | Required |
Bucket | String | Bucket name in the format of BucketName-APPID | Yes |
Key | String | Uniquely identifies an object in a bucket. For example, if the object access endpoint is examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg , its object key is doc/pic.jpg . | Yes |
Guzzle\\Service\\Resource\\Model Object([structure:protected] =>[data:protected] => Array([Body] =>[RequestId] => NWQwOGRkNDdfMjJiMjU4NjRfNzVjXzEwNmVjY2M=[ContentLength] => 100[ContentType] => application/json[Key] => exampleobject[Bucket] => examplebucket-1250000000[Location] => examplebucket-1250000000.cos.ap-beijing.myqcloud.com/exampleobject[Data] => {"format": "jpeg", "width": "400", "height": "400"}))
Parameter | Type | Description | Parent Node |
Body | File/String | Response body | None |
RequestId | String | Request ID | None |
ContentType | String | Content type. Sets Content-Type | None |
ContentLength | Int | Length of the response body | None |
Key | String | Object key | None |
Bucket | String | Bucket name in the format of BucketName-APPID | None |
Location | String | Address of the requested resource | None |
Data | Json/String | Basic image information | None |
{"error" : "no exif data"}
will be returned.<?phprequire dirname(__FILE__) . '/../vendor/autoload.php';$secretId = "SECRETID"; //Replace it with the actual SecretId, which can be viewed and managed at https://console.tencentcloud.com/cam/capi$secretKey = "SECRETKEY"; //Replace it with the actual SecretKey, which can be viewed and managed at https://console.tencentcloud.com/cam/capi$region = "ap-beijing"; //Replace it with the actual region, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket$cosClient = new Qcloud\\Cos\\Client(array('region' => $region,'schema' => 'https', // Protocol header, which is http by default'credentials'=> array('secretId' => $secretId ,'secretKey' => $secretKey)));try {$result = $cosClient->ImageExif(array('Bucket' => 'examplebucket-1250000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket'Key' => 'exampleobject',));// Request succeededprint_r($result);} catch (\\Exception $e) {// Request failedecho($e);}
Parameter | Type | Description | Required |
Bucket | String | Bucket name in the format of BucketName-APPID | Yes |
Key | String | Uniquely identifies an object in a bucket. For example, if the object access endpoint is examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg , its object key is doc/pic.jpg . | Yes |
Guzzle\\Service\\Resource\\Model Object([structure:protected] =>[data:protected] => Array([Body] =>[RequestId] => NWQwOGRkNDdfMjJiMjU4NjRfNzVjXzEwNmVjY2M=[ContentLength] => 32[ContentType] => application/json[Key] => exampleobject[Bucket] => examplebucket-1250000000[Location] => examplebucket-1250000000.cos.ap-beijing.myqcloud.com/exampleobject[Data] => {"error" : "no exif data"}))
Parameter | Type | Description | Parent Node |
Body | File/String | Response body | None |
RequestId | String | Request ID | None |
ContentType | String | Content type. Sets Content-Type | None |
ContentLength | Int | Length of the response body | None |
Key | String | Object key | None |
Bucket | String | Bucket name in the format of BucketName-APPID | None |
Location | String | Address of the requested resource | None |
Data | Json/String | Image EXIF data | None |
<?phprequire dirname(__FILE__) . '/../vendor/autoload.php';$secretId = "SECRETID"; //Replace it with the actual SecretId, which can be viewed and managed at https://console.tencentcloud.com/cam/capi$secretKey = "SECRETKEY"; //Replace it with the actual SecretKey, which can be viewed and managed at https://console.tencentcloud.com/cam/capi$region = "ap-beijing"; //Replace it with the actual region, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket$cosClient = new Qcloud\\Cos\\Client(array('region' => $region,'schema' => 'https', // Protocol header, which is http by default'credentials'=> array('secretId' => $secretId ,'secretKey' => $secretKey)));try {$result = $cosClient->ImageAve(array('Bucket' => 'examplebucket-1250000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket'Key' => 'exampleobject',));// Request succeededprint_r($result);} catch (\\Exception $e) {// Request failedecho($e);}
Parameter | Type | Description | Required |
Bucket | String | Bucket name in the format of BucketName-APPID | Yes |
Key | String | Uniquely identifies an object in a bucket. For example, if the object access endpoint is examplebucket-1250000000.cos.ap-guangzhou.myqcloud.com/doc/pic.jpg , its object key is doc/pic.jpg . | Yes |
Guzzle\\Service\\Resource\\Model Object([structure:protected] =>[data:protected] => Array([Body] =>[RequestId] => NWQwOGRkNDdfMjJiMjU4NjRfNzVjXzEwNmVjY2M=[ContentLength] => 19[ContentType] => application/json[Key] => exampleobject[Bucket] => examplebucket-1250000000[Location] => examplebucket-1250000000.cos.ap-beijing.myqcloud.com/exampleobject[Data] => {"RGB": "0x483519"}))
Parameter | Type | Description | Parent Node |
Body | File/String | Response body | None |
RequestId | String | Request ID | None |
ContentType | String | Content type. Sets Content-Type | None |
ContentLength | Int | Length of the response body | None |
Key | String | Object key | None |
Bucket | String | Bucket name in the format of BucketName-APPID | None |
Location | String | Address of the requested resource | None |
Data | Json/String | Average hue of the image | None |
$imageMogrTemplate->strip(); //Remove image metadata
<?phprequire dirname(__FILE__) . '/../vendor/autoload.php';$secretId = "SECRETID"; //Replace it with the actual SecretId, which can be viewed and managed at https://console.tencentcloud.com/cam/capi$secretKey = "SECRETKEY"; //Replace it with the actual SecretKey, which can be viewed and managed at https://console.tencentcloud.com/cam/capi$region = "ap-beijing"; //Replace it with the actual region, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket$cosClient = new Qcloud\\Cos\\Client(array('region' => $region,'schema' => 'https', // Protocol header, which is http by default'credentials'=> array('secretId' => $secretId ,'secretKey' => $secretKey)));try {$imageViewTemplate = new Qcloud\\Cos\\ImageParamTemplate\\ImageViewTemplate(); //Create a parameter template instance for the quick thumbnail template$imageViewTemplate->setMode(1); //Set the thumbnail mode. Value range: [1,5]. Mode 1: specify the minimum width and height of the thumbnail. In this mode, the image is first scaled down until one of the minimum values set is reached. Then, the image will be centered and evenly cropped on both sides to meet the specified values. If only one value is set, a square thumbnail will be generated. Mode 2: specify the maximum width and height of the thumbnail. In this mode, the image is scaled down until both the width and length are not greater than the maximum values set. Mode 3: specify the minimum width and height of the thumbnail. In this mode, the image is scaled down until both the width and height are not smaller than the minimum values set. Mode 4: specify the minimum values of the long edge and short edge of the thumbnail to scale down the image. If only one value is set, a square thumbnail will be generated. Mode 5: specify the maximum values of the long edge and short edge of the thumbnail to scale down the image. Then the image will be centered and cropped. If only one value is set, a square thumbnail will be generated. After the scaling, the excess will be cropped.$imageViewTemplate->setWidth(400); //Set the thumbnail width$imageViewTemplate->setHeight(600); //Set the thumbnail height$imageViewTemplate->setFormat(); //Set the thumbnail format, which can be JPG, BMP, GIF, PNG, or WebP. Default value: format of the input image$imageViewTemplate->setQuality(1, 85); //Set the image quality type, which can be `1` (absolute quality), `2` (relative quality), or `3` (lowest quality)$imageViewTemplate->setQuality(1, 85, 1); //If the image quality type is set to absolute quality, the specified quality will be used by force$result = $cosClient->getObject(array('Bucket' => 'examplebucket-1250000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket'Key' => 'exampleobject','ImageHandleParam' => $imageViewTemplate->queryString(), //Generate quick thumbnail template parameters));// Request succeededprint_r($result);} catch (\\Exception $e) {// Request failedecho($e);}
<?phprequire dirname(__FILE__) . '/../vendor/autoload.php';$secretId = "SECRETID"; //Replace it with the actual SecretId, which can be viewed and managed at https://console.tencentcloud.com/cam/capi$secretKey = "SECRETKEY"; //Replace it with the actual SecretKey, which can be viewed and managed at https://console.tencentcloud.com/cam/capi$region = "ap-beijing"; //Replace it with the actual region, which can be viewed in the console at https://console.tencentcloud.com/cos5/bucket$cosClient = new Qcloud\\Cos\\Client(array('region' => $region,'schema' => 'https', // Protocol header, which is http by default'credentials'=> array('secretId' => $secretId ,'secretKey' => $secretKey)));try {$ciParamTransformation = new Qcloud\\Cos\\ImageParamTemplate\\CIParamTransformation(); //Create a pipeline parameter template instance$ciParamTransformation = new Qcloud\\Cos\\ImageParamTemplate\\CIParamTransformation("#"); //If the pipeline operator is not `|`, it must be specified during instance creation$ciParamTransformation->addRule($imageMogrTemplate); //Set basic image processing parameters$ciParamTransformation->addRule($imageWatermarkTemplate); //Set image watermark processing parameters$ciParamTransformation->addRule($textWatermarkTemplate); //Set text watermark processing parameters$ciParamTransformation->addRule($imageViewTemplate); //Set quick thumbnail template parameters$result = $cosClient->getObject(array('Bucket' => 'examplebucket-1250000000', // Bucket name in the format of `BucketName-APPID`, which can be viewed in the COS console at https://console.tencentcloud.com/cos5/bucket'Key' => 'exampleobject','ImageHandleParam' => $ciParamTransformation->queryString(), //Generate pipeline splicing parameters));// Request succeededprint_r($result);} catch (\\Exception $e) {// Request failedecho($e);}
Apakah halaman ini membantu?