ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
34  return self::$supported_formats;
35  }

◆ isGhostscriptInstalled()

static ilGhostscriptRenderer::isGhostscriptInstalled ( )
static

Determines whether Ghostscript is installed.

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

Referenced by ilObjFileAccessSettingsGUI\editPreviewSettings(), and ilRendererFactory\loadAvailableRenderers().

41  {
42  return (PATH_TO_GHOSTSCRIPT != "");
43  }
+ 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 52 of file class.ilGhostscriptRenderer.php.

References $i, Sabre\VObject\$output, $outputFile, ilUtil\escapeShellArg(), ilUtil\execQuoted(), ilPreviewRenderer\getMaximumNumberOfPreviews(), ilUtil\ilTempnam(), and ilFilePreviewRenderer\prepareFileForExec().

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