diff --git a/CHANGES.md b/CHANGES.md index 3322978..75d5cc8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,7 @@ ## 1.6.0 * Support to run the unittests on newer versions of PHP (5.5 +) -* Add API methods for transcoding and transformation +* Add API methods for converting/transcoding and transformation +* Add helper function for returning the compressed file extension ## 1.5.2 * Fail early if version of curl/openssl is too old. diff --git a/lib/Tinify/ResultMeta.php b/lib/Tinify/ResultMeta.php index 337a48f..27aba0e 100644 --- a/lib/Tinify/ResultMeta.php +++ b/lib/Tinify/ResultMeta.php @@ -20,4 +20,12 @@ public function height() { public function location() { return isset($this->meta["location"]) ? $this->meta["location"] : null; } + + public function extension() { + if (isset($this->meta["content-type"])) { + $parts = explode("/", $this->meta["content-type"]); + return end($parts); + } + return null; + } } diff --git a/test/TinifyResultTest.php b/test/TinifyResultTest.php index 81687c5..94e3406 100644 --- a/test/TinifyResultTest.php +++ b/test/TinifyResultTest.php @@ -32,4 +32,14 @@ public function testWithMetaAndDataToBufferShouldReturnImageData() { $result = new Tinify\Result(array(), "image data"); $this->assertSame("image data", $result->toBuffer()); } + + public function testWithMetadataReturnsExtension() { + $result = new Tinify\Result(array("content-type" => "image/png"), "image data"); + $this->assertSame($result->extension(), "png"); + } + + public function testWithoutMetadataReturnsExtensionAsNull() { + $result = new Tinify\ResultMeta(array(), "image data"); + $this->assertSame($result->extension(), null); + } }