Skip to content

Commit

Permalink
Issue #258 Add toString() method to Image
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehaertl committed Dec 31, 2017
1 parent dccea43 commit a53d591
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@ public function send($filename = null,$inline = false)
return true;
}

/**
* Get the raw Image contents (triggers Image creation).
* @return string|bool The Image content as a string or `false` if the
* Image wasn't created successfully.
*/
public function toString()
{
if (!$this->_isCreated && !$this->createImage()) {
return false;
}
return file_get_contents($this->_tmpImageFile->getFileName());
}

/**
* Set options
*
Expand Down
15 changes: 15 additions & 0 deletions tests/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ public function testCanSetPageFromUrl()
unlink($outFile);
}

public function testToString()
{
$outFile = $this->getOutFile('png');
$binary = $this->getBinary();

$image = new Image('<html><h1>Test</h1></html>');
$image->binary = $binary;

$this->assertTrue($image->saveAs($outFile));
$this->assertFileExists($outFile);

$this->assertEquals(file_get_contents($outFile), $image->toString());
unlink($outFile);
}

// Options
public function testCanOptionsInConstructor()
{
Expand Down

0 comments on commit a53d591

Please sign in to comment.