ILIAS  release_4-4 Revision
ilGhostscriptRenderer Class Reference

Preview renderer class that is able to create previews from PDF, PS and EPS by using GhostScript. More...

+ Inheritance diagram for ilGhostscriptRenderer:
+ Collaboration diagram for ilGhostscriptRenderer:

Public Member Functions

 getSupportedFileFormats ()
 Gets an array containing the file formats that are supported by the renderer. More...
 
- Public Member Functions inherited from ilFilePreviewRenderer
 getSupportedRepositoryTypes ()
 Gets an array containing the repository types (e.g. More...
 
 supports ($preview)
 Determines whether the specified preview object is supported by the renderer. More...
 
 prepareFileForExec ($filepath)
 Checks whether the specified file path can be used with exec() commands. More...
 
 getSupportedFileFormats ()
 Gets an array containing the file formats that are supported by the renderer. More...
 
- Public Member Functions inherited from ilPreviewRenderer
 getName ()
 Gets the name of the renderer. More...
 
 isPlugin ()
 Determines whether the renderer is a plugin or a built in one. More...
 
 getSupportedRepositoryTypes ()
 Gets an array containing the repository types (e.g. More...
 
 supports ($preview)
 Determines whether the specified preview object is supported by the renderer. More...
 
 render ($preview, $obj, $async)
 Creates the preview of the specified preview object. More...
 

Static Public Member Functions

static isGhostscriptInstalled ()
 Determines whether Ghostscript is installed. More...
 

Data Fields

const SUPPORTED_FORMATS = "eps,pdf,pdfa,ps"
 

Protected Member Functions

 renderImages ($obj)
 Renders the specified object into images. More...
 
- Protected Member Functions inherited from ilPreviewRenderer
 renderImages ($obj)
 Renders the specified object into images. More...
 
 getImageSize ()
 Gets the size of the preview images in pixels. More...
 
 getImageQuality ()
 Gets the quality (compression) of the preview images (1-100). More...
 
 getMaximumNumberOfPreviews ()
 Gets the maximum number of preview pictures per object. More...
 

Static Private Attributes

static $supported_formats = null
 

Detailed Description

Preview renderer class that is able to create previews from PDF, PS and EPS by using GhostScript.

Author
Stefan Born stefa.nosp@m.n.bo.nosp@m.rn@ph.nosp@m.zh.c.nosp@m.h
Version
$Id$

Definition at line 14 of file class.ilGhostscriptRenderer.php.

Member Function Documentation

◆ getSupportedFileFormats()

ilGhostscriptRenderer::getSupportedFileFormats ( )

Gets an array containing the file formats that are supported by the renderer.

Returns
array An array containing the supported file formats.

Definition at line 27 of file class.ilGhostscriptRenderer.php.

28  {
29  // build formats only once
30  if (self::$supported_formats == null)
31  self::$supported_formats = explode(",", self::SUPPORTED_FORMATS);
32 
33  return self::$supported_formats;
34  }

◆ isGhostscriptInstalled()

static ilGhostscriptRenderer::isGhostscriptInstalled ( )
static

Determines whether Ghostscript is installed.

Definition at line 39 of file class.ilGhostscriptRenderer.php.

Referenced by ilRendererFactory\loadAvailableRenderers().

40  {
41  return (PATH_TO_GHOSTSCRIPT != "");
42  }
+ Here is the caller graph for this function:

◆ renderImages()

ilGhostscriptRenderer::renderImages (   $obj)
protected

Renders the specified object into images.

The images do not need to be of the preview image size.

Parameters
ilObjFile$objThe object to create images from.
Returns
array An array of ilRenderedImage containing the absolute file paths to the images.

Definition at line 51 of file class.ilGhostscriptRenderer.php.

References ilUtil\escapeShellArg(), ilUtil\execQuoted(), ilPreviewRenderer\getMaximumNumberOfPreviews(), ilUtil\ilTempnam(), and ilFilePreviewRenderer\prepareFileForExec().

52  {
53  $numOfPreviews = $this->getMaximumNumberOfPreviews();
54 
55  // get file path
56  $filepath = $obj->getFile();
57  $inputFile = $this->prepareFileForExec($filepath);
58 
59  // create a temporary file name and remove its extension
60  $output = str_replace(".tmp", "", ilUtil::ilTempnam());
61 
62  // use '#' instead of '%' as it gets replaced by 'escapeShellArg' on windows!
63  $outputFile = $output . "_#02d.png";
64 
65  // create images with ghostscript (we use PNG here as it has better transparency quality)
66  // gswin32c -dBATCH -dNOPAUSE -dSAFER -dFirstPage=1 -dLastPage=5 -sDEVICE=pngalpha -dEPSCrop -r72 -o $outputFile $inputFile
67  // gswin32c -dBATCH -dNOPAUSE -dSAFER -dFirstPage=1 -dLastPage=5 -sDEVICE=jpeg -dJPEGQ=90 -r72 -o $outputFile $inputFile
68  $args = sprintf(
69  "-dBATCH -dNOPAUSE -dSAFER -dFirstPage=1 -dLastPage=%d -sDEVICE=pngalpha -dEPSCrop -r72 -o %s %s",
70  $numOfPreviews,
71  str_replace("#", "%", ilUtil::escapeShellArg($outputFile)),
72  ilUtil::escapeShellArg($inputFile));
73 
74  ilUtil::execQuoted(PATH_TO_GHOSTSCRIPT, $args);
75 
76  // was a temporary file created? then delete it
77  if ($filepath != $inputFile)
78  @unlink($inputFile);
79 
80  // check each file and add it
81  $images = array();
82  $outputFile = str_replace("#", "%", $outputFile);
83 
84  for ($i = 1; $i <= $numOfPreviews; $i++)
85  {
86  $imagePath = sprintf($outputFile, $i);
87  if (!file_exists($imagePath))
88  break;
89 
90  $images[] = new ilRenderedImage($imagePath);
91  }
92 
93  return $images;
94  }
prepareFileForExec($filepath)
Checks whether the specified file path can be used with exec() commands.
getMaximumNumberOfPreviews()
Gets the maximum number of preview pictures per object.
static execQuoted($cmd, $args=NULL)
exec command and fix spaces on windows
Represents an image that was created from a preview renderer and that can be further processed to cre...
static ilTempnam()
Create a temporary file in an ILIAS writable directory.
static escapeShellArg($a_arg)
+ Here is the call graph for this function:

Field Documentation

◆ $supported_formats

ilGhostscriptRenderer::$supported_formats = null
staticprivate

Definition at line 20 of file class.ilGhostscriptRenderer.php.

◆ SUPPORTED_FORMATS

const ilGhostscriptRenderer::SUPPORTED_FORMATS = "eps,pdf,pdfa,ps"

Definition at line 17 of file class.ilGhostscriptRenderer.php.


The documentation for this class was generated from the following file: