Skip to content

Commit

Permalink
Allows better control over result-filename
Browse files Browse the repository at this point in the history
This fixes #7
  • Loading branch information
heiglandreas committed Jun 16, 2017
1 parent f9a822d commit e3e2343
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Ghostscript.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public function getRenderString()
}
$string = self::getGsPath();
$string .= ' -dSAFER -dQUIET -dNOPLATFONTS -dNOPAUSE -dBATCH';
$string .= ' -sOutputFile="' . $this->getOutputFile() . '.' . $this->getDevice()->getFileEnding() . '"';
$string .= ' -sOutputFile="' . $this->getOutputFileName() . '"';
$string .= $this->getDevice()->getParameterString();
$string .= ' -r' . $this->getResolution();
if ($this->isTextAntiAliasingSet()) {
Expand Down Expand Up @@ -878,6 +878,17 @@ public function setPages($startPage, $endPage = null)

return $this;
}

public function getOutputFileName()
{
$basename = $this->getOutputFile();
$lastDot = strrpos('.', basename($basename));
if (false === $lastDot) {
return $basename . '.' . $this->getDevice()->getFileEnding();
}

return $basename;
}
}

try {
Expand Down
22 changes: 22 additions & 0 deletions tests/GhostscriptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ public function testSettingOutfileWorks()
$this->assertEquals('/some/other/test', $f->getOutputFile());
}

/**
* @dataProvider settingOutfileIsRepresentedInRenderStringProvider
*/
public function testSettingOutfileIsRepresentedInRenderString($outfile, $expectedResultInRenderString)
{
$f = new Ghostscript();
$f->setDevice(new Png());
$f->setInputFile(__DIR__ . '/support/test.pdf');
$f->setOutputFile($outfile);
$this->assertContains($expectedResultInRenderString, $f->getRenderString());
}

public function settingOutfileIsRepresentedInRenderStringProvider()
{
return [
['test', __DIR__ . '/support/test'],
['/this/is/a/test', '/this/is/a/test'],
['test.jpeg', __DIR__ . '/support/test.jpeg'],
['/this/is/a/test.jpeg', '/this/is/a/test.jpeg'],
];
}

public function testDefaultDevice()
{
$f = new Ghostscript();
Expand Down

0 comments on commit e3e2343

Please sign in to comment.