diff --git a/tests/OSS/Tests/OssClientImageTest.php b/tests/OSS/Tests/OssClientImageTest.php new file mode 100644 index 00000000..73c5f2fd --- /dev/null +++ b/tests/OSS/Tests/OssClientImageTest.php @@ -0,0 +1,108 @@ +client = Common::getOssClient(); + $this->bucketName = 'php-sdk-test-bucket-image-' . strval(rand(0, 10)); + $this->client->createBucket($this->bucketName); + Common::waitMetaSync(); + sleep(30); + $this->local_file = "example.jpg"; + $this->object = "oss-example.jpg"; + $this->download_file = "image.jpg"; + + $this->client->uploadFile($this->bucketName, $this->object, $this->local_file); + } + + public function tearDown() + { + $this->client->deleteObject($this->bucketName, $this->object); + $this->client->deleteBucket($this->bucketName); + } + + public function testImageResize() + { + $options = array( + OssClient::OSS_FILE_DOWNLOAD => $this->download_file, + 'x-oss-process' => "image/resize,m_fixed,h_100,w_100", ); + $this->check($options, 100, 100, 3587, 'jpg'); + } + + public function testImageCrop() + { + $options = array( + OssClient::OSS_FILE_DOWNLOAD => $this->download_file, + 'x-oss-process' => "image/crop,w_100,h_100,x_100,y_100,r_1", ); + $this->check($options, 100, 100, 2281, 'jpg'); + } + + public function testImageRotate() + { + $options = array( + OssClient::OSS_FILE_DOWNLOAD => $this->download_file, + 'x-oss-process' => "image/rotate,90", ); + $this->check($options, 267, 400, 21509, 'jpg'); + } + + public function testImageSharpen() + { + $options = array( + OssClient::OSS_FILE_DOWNLOAD => $this->download_file, + 'x-oss-process' => "image/sharpen,100", ); + $this->check($options, 400, 267, 24183, 'jpg'); + } + + public function testImageWatermark() + { + $options = array( + OssClient::OSS_FILE_DOWNLOAD => $this->download_file, + 'x-oss-process' => "image/watermark,text_SGVsbG8g5Zu-54mH5pyN5YqhIQ", ); + $this->check($options, 400, 267, 26953, 'jpg'); + } + + public function testImageFormat() + { + $options = array( + OssClient::OSS_FILE_DOWNLOAD => $this->download_file, + 'x-oss-process' => "image/format,png", ); + $this->check($options, 400, 267, 160733, 'png'); + } + + public function testImageTofile() + { + $options = array( + OssClient::OSS_FILE_DOWNLOAD => $this->download_file, + 'x-oss-process' => "image/resize,m_fixed,w_100,h_100", ); + $this->check($options, 100, 100, 3587, 'jpg'); + } + + private function check($options, $width, $height, $size, $type) + { + $this->client->getObject($this->bucketName, $this->object, $options); + $array = getimagesize($this->download_file); + $this->assertEquals($width, $array[0]); + $this->assertEquals($height, $array[1]); + $this->assertEquals($type === 'jpg' ? 2 : 3, $array[2]);//2 <=> jpg + $this->assertEquals($size, ceil(filesize($this->download_file))); + } +}