public function testRenderingStrings() { $f = new Ghostscript(); $dir = __DIR__ . DIRECTORY_SEPARATOR . 'support' . DIRECTORY_SEPARATOR; $filename = $dir . 'test.pdf'; $path = Ghostscript::getGsPath(); $this->assertEquals('', $f->getRenderString()); $f->setInputFile($filename); $expect = $path . ' -dSAFER -dQUIET -dNOPLATFONTS -dNOPAUSE -dBATCH -sOutputFile="' . $dir . 'output.png" -sDEVICE=pngalpha -r72 "' . $filename . '"'; $this->assertEquals($expect, $f->getRenderString()); $f->setTextAntiAliasing(Ghostscript::ANTIALIASING_HIGH); $expect = $path . ' -dSAFER -dQUIET -dNOPLATFONTS -dNOPAUSE -dBATCH -sOutputFile="' . $dir . 'output.png" -sDEVICE=pngalpha -r72 -dTextAlphaBits=4 "' . $filename . '"'; $this->assertEquals($expect, $f->getRenderString()); $f->setGraphicsAntiAliasing(Ghostscript::ANTIALIASING_HIGH); $expect = $path . ' -dSAFER -dQUIET -dNOPLATFONTS -dNOPAUSE -dBATCH -sOutputFile="' . $dir . 'output.png" -sDEVICE=pngalpha -r72 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "' . $filename . '"'; $this->assertEquals($expect, $f->getRenderString()); $f->setTextAntiAliasing(Ghostscript::ANTIALIASING_NONE); $expect = $path . ' -dSAFER -dQUIET -dNOPLATFONTS -dNOPAUSE -dBATCH -sOutputFile="' . $dir . 'output.png" -sDEVICE=pngalpha -r72 -dGraphicsAlphaBits=4 "' . $filename . '"'; $this->assertEquals($expect, $f->getRenderString()); $f->setDevice('jpeg'); $expect = $path . ' -dSAFER -dQUIET -dNOPLATFONTS -dNOPAUSE -dBATCH -sOutputFile="' . $dir . 'output.jpeg" -sDEVICE=jpeg -dJPEGQ=75 -dQFactor=0.75 -r72 -dGraphicsAlphaBits=4 "' . $filename . '"'; $this->assertEquals($expect, $f->getRenderString()); }
/** * Get the command-line that can be executed via exec * * @return string */ public function getRenderString() { if (null === $this->getInputFile()) { return ''; } $string = Ghostscript::getGsPath(); $string .= ' -dSAFER -dQUIET -dNOPLATFONTS -dNOPAUSE -dBATCH'; $string .= ' -sOutputFile="' . $this->getOutputFile() . '.' . $this->getDevice()->getFileEnding() . '"'; $string .= $this->getDevice()->getParameterString(); $string .= ' -r' . $this->getResolution(); if ($this->isTextAntiAliasingSet()) { $string .= ' -dTextAlphaBits=' . $this->getTextAntiAliasing(); } if ($this->isGraphicsAntiAliasingSet()) { $string .= ' -dGraphicsAlphaBits=' . $this->getGraphicsAntiAliasing(); } $string .= $this->getPageRangeString(); $string .= ' "' . $this->getInputFile() . '"'; return $string; }