\Org_Heigl\GhostscriptGhostscript

This class contains a wrapper around the Ghostscript-Application.

This needs the Ghostscript application to be installed on the server. If the gs-executable is not available the class will not be able to execute anything

A working example might look like the following code:

// First we describe the output-format $device = new Org_Heigl_Ghostscript_Device_Jpeg ();

// Set the JPEG-Quality to 100 $device -> setQuality ( 100 );

// Next we Create the ghostscript-Wrapper $gs = new Org_Heigl_Ghostscript ();

// Set the device $gs -> setDevice ( $device ) // Set the input file -> setInputFile ( 'path/to/my/ps/or/pdf/file' ) // Set the output file that will be created in the same directory as the input -> setOutputFile ( 'output' ) // Set the resolution to 96 pixel per inch -> setResolution ( 96 ) // Set Text-antialiasing to the highest level -> setTextAntiAliasing ( Org_Heigl_Ghostscript::ANTIALIASING_HIGH );

// convert the input file to an image if ( true === $gs -> render () ) { echo 'success'; } else { echo 'some error occured'; }

Alternatively the example could read as follows

// Create the ghostscript-Wrapper $gs = new Org_Heigl_Ghostscript ();

// Set the device $gs -> setDevice ( 'jpeg' ) // Set the input file -> setInputFile ( 'path/to/my/ps/or/pdf/file' ) // Set the output file that will be created in the same directory as the input -> setOutputFile ( 'output' ) // Set the resolution to 96 pixel per inch -> setResolution ( 96 ) // Set Text-antialiasing to the highest level -> setTextAntiAliasing ( Org_Heigl_Ghostscript::ANTIALIASING_HIGH );

// Set the jpeg-quality to 100 $gs -> getDevice () -> setQuality ( 100 );

// convert the input file to an image if ( true === $gs -> render () ) { echo 'success'; } else { echo 'some error occured'; }

Summary

Methods
Properties
Constants
__construct()
setGsPath()
getGsPath()
setInputFile()
getInputFile()
setOutputFile()
getOutputFile()
getBasePath()
render()
getRenderString()
getPageRangeString()
isGraphicsAntiAliasingSet()
setGraphicsAntiAliasing()
getGraphicsAntiAliasing()
isTextAntiAliasingSet()
setTextAntiAliasing()
getTextAntiAliasing()
setResolution()
getResolution()
setDevice()
getDevice()
setUseCie()
useCie()
useBox()
getBox()
setDefaultProfile()
getDefaultProfile()
setDeviceProfile()
getDeviceProfile()
setPageStart()
setPageEnd()
setPages()
getOutputFileName()
No public properties found
ANTIALIASING_NONE
ANTIALIASING_LOW
ANTIALIASING_MEDIUM
ANTIALIASING_HIGH
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Constants

ANTIALIASING_NONE

ANTIALIASING_NONE

No Anti-Aliasing

ANTIALIASING_LOW

ANTIALIASING_LOW

Low Anti-Aliasing

ANTIALIASING_MEDIUM

ANTIALIASING_MEDIUM

Medium Anti-Aliasing

ANTIALIASING_HIGH

ANTIALIASING_HIGH

High Anti-Aliasing

Methods

__construct()

__construct() : void

Create a new Instance of the Ghostscript wrapper.

The new Instance will use a jpeg-device as default

setGsPath()

setGsPath(string|null  $path = null) : string

Set the path to the gs-executable and return it.

This method will be called on load of the class and needs not to be called during normal operation.

If you have Ghostscript installed in a non-standard-location that can not be found via the 'which gs' command, you have to set the path manualy

Parameters

string|null $path

The path to set

Returns

string

getGsPath()

getGsPath() : string

Get the currently set path for the ghostscript-app

Returns

string

setInputFile()

setInputFile(string|\Org_Heigl\Ghostscript\SplFileInfo  $file) : self

Set the file that shall be processes

This should be a PostScript (ps), Enhanced Postscript (eps) or PortableDocumentformat (pdf) File.

Parameters

string|\Org_Heigl\Ghostscript\SplFileInfo $file

The File to use as input.

Throws

\Org_Heigl\Ghostscript\InvalidArgumentException

when the provided file is not supported

Returns

self

getInputFile()

getInputFile() : \Org_Heigl\Ghostscript\SplFileInfo

Get the file that shall be processed

Returns

\Org_Heigl\Ghostscript\SplFileInfo

setOutputFile()

setOutputFile(string  $name = 'output') : \Org_Heigl\Ghostscript\Ghostscript

Set the name of the output file(s)

This name does not need a file-extension as that is set from the output format.

The name can contain a placeholder like '%d' or '%02d'. This will be replaced by the pagenumber of the processed page. For more information on the format see the PHP documentation for sprintf

Parameters

string $name

The filename

Returns

\Org_Heigl\Ghostscript\Ghostscript

getOutputFile()

getOutputFile() : string

Get the output filename.

This is NOT the name the file can be retrieved with as Ghostscript can modify the filename, but the returned string containes the directory the file(s) reside in.

Returns

string

getBasePath()

getBasePath() : string

Get the basepath of the execution.

Thisis set to the directory containing $_infile.

If $_infile is not set, it is set to the systems default tmp-directory.

Returns

string

render()

render() : boolean

Render the input file via Ghostscript

Returns

boolean

getRenderString()

getRenderString() : string

Get the command-line that can be executed via exec

Returns

string

getPageRangeString()

getPageRangeString() 

isGraphicsAntiAliasingSet()

isGraphicsAntiAliasingSet() : boolean

Check whether Anti ALiasing for graphics is set

Returns

boolean

setGraphicsAntiAliasing()

setGraphicsAntiAliasing(integer  $level) : self

Set graphics-AntiAliasing

Parameters

integer $level

The AntiaAliasing level to set.

Returns

self

getGraphicsAntiAliasing()

getGraphicsAntiAliasing() : integer

Get the text-AntiAliasing level

Returns

integer

isTextAntiAliasingSet()

isTextAntiAliasingSet() : boolean

Check whether Anti ALiasing for text is set

Returns

boolean

setTextAntiAliasing()

setTextAntiAliasing(integer  $level) : self

Set text-AntiAliasing

Parameters

integer $level

The AntiaAliasing level to set.

Returns

self

getTextAntiAliasing()

getTextAntiAliasing() : integer

Get the text-AntiAliasing level

Returns

integer

setResolution()

setResolution(  $horizontal,   $vertical = null) : self

Set the resolution for the rendering

Parameters

$horizontal
$vertical

Returns

self

getResolution()

getResolution() : string

Get the resolution

Returns

string

setUseCie()

setUseCie(  $useCie = true) : self

Set whether to use the CIE-Map for conversion between CMYK and RGB or not

Parameters

$useCie

Returns

self

useCie()

useCie() : boolean

Shall we use the CIE map for color-conversions?

Returns

boolean

useBox()

useBox(string  $box) 

Which Box shall be used to generate the output from.

This can be one of

  • crop
  • media

Parameters

string $box

The box to use

@return self

getBox()

getBox() : string|null

Get the name of the box to be used for rendering

This returns either 'crop' or 'media' if one of these boxes shall be rendered or NULL if the switch shall not be set.

Returns

string|null

setDefaultProfile()

setDefaultProfile(string  $profile, string  $space = null) : self

Add the given Profile for Color-Management as Input-Profile.

The Profile will be added as CSA-File to perform the translation of Colors from the Input-File to the Internal ProcessColosSpace.

The CSA-File can be created via the OpenSource-Tool icc2ps from the littleCMS-Package available at http://www.littlecms.org

The CSA-File can be generated via the following command from any icc-file: icc2ps -i > output.csa This gerneated CSA-File has to be adapted according to the following example: currentglobal true setglobal /DefaultCMYK [ /CIEBasedDEFG << ... ...

] /ColorSpace defineresource pop setglobal where the Part in the brackets is the part that is generated from the icc2ps-tool.

For more Information on Color-Conversion and Color-Management refer to the Homepage of ghostscript, the ICC or have a look at a Search-Engine.

Parameters

string $profile

The Name of the CSA-Profile to use or the complete path to an appropriate CSA-File.

string $space

The Color-Space to set the profile for. This can be one of 'rgb', 'cmyk' or 'gray'. This parameter is currently not supported!

Returns

self

getDefaultProfile()

getDefaultProfile(  $space = 'cmyk') : string|false

Get the default Input-Profile

Parameters

$space

Returns

string|false

setDeviceProfile()

setDeviceProfile(string  $profile) : self

Add the given Profile for Color-Management as Device-Output-Profile.

The Profile will be added as CRD-File to perform the translation of Colors from the Internal ProcessColorSpace to the Output-File.

The CRD-File can be created via the OpenSource-Tool icc2ps from the littleCMS-Package available at http://www.littlecms.org

The CRD-File can be generated via the following command from any icc-file: icc2ps -o > output.crd This gerneated CRD-File has to be adapted by appeding the following line to it: /Current /ColorRendering findresource setcolorrendering

For more Information on Color-Conversion and Color-Management refer to the Homepage of ghostscript, the ICC or have a look at a Search-Engine.

Parameters

string $profile

The Name of the CRD-Profile to use or the complete path to an appropriate CRD-File.

Returns

self

getDeviceProfile()

getDeviceProfile() : string|false

Get the currently set device-Profile

Returns

string|false

setPageStart()

setPageStart(integer  $page) : self

Set the page to start rendering

Parameters

integer $page

Returns

self

setPageEnd()

setPageEnd(integer  $page) : self

Set the page to stop rendering

Parameters

integer $page

Returns

self

setPages()

setPages(  $startPage,   $endPage = null) : self

Set a page-Range

Parameters

$startPage
$endPage

Returns

self

getOutputFileName()

getOutputFileName()