Skip to content

Commit

Permalink
Add method for returning file extension
Browse files Browse the repository at this point in the history
  • Loading branch information
rkoopmans committed Sep 20, 2022
1 parent b527106 commit 2165f0b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
8 changes: 8 additions & 0 deletions lib/Tinify/ResultMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
10 changes: 10 additions & 0 deletions test/TinifyResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 2165f0b

Please sign in to comment.