ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilGhostscriptRenderer Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. 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 (\ilPreview $preview)
 Determines whether the specified preview object is supported by the renderer. More...
 
 prepareFileForExec (string $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 (\ilPreview $preview)
 Determines whether the specified preview object is supported by the renderer. More...
 
 render (\ilPreview $preview, \ilObject $obj, bool $async)
 Creates the preview of the specified preview object. More...
 

Static Public Member Functions

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

Protected Member Functions

 renderImages (\ilObject $obj)
 Renders the specified object into images. More...
 
- Protected Member Functions inherited from ilPreviewRenderer
 renderImages (\ilObject $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...
 

Private Attributes

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

Static Private Attributes

static array $supported_formats = null
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning 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 26 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 38 of file class.ilGhostscriptRenderer.php.

38  : array
39  {
40  // build formats only once
41  if (!isset(self::$supported_formats)) {
42  self::$supported_formats = explode(",", self::SUPPORTED_FORMATS);
43  }
44 
45  return self::$supported_formats;
46  }

◆ isGhostscriptInstalled()

static ilGhostscriptRenderer::isGhostscriptInstalled ( )
static

Determines whether Ghostscript is installed.

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

Referenced by ilObjFileAccessSettingsGUI\showPreviewRenderers().

51  : bool
52  {
53  return (defined('PATH_TO_GHOSTSCRIPT') && PATH_TO_GHOSTSCRIPT !== "");
54  }
+ Here is the caller graph for this function:

◆ renderImages()

ilGhostscriptRenderer::renderImages ( \ilObject  $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
ilRenderedImage[] An array of ilRenderedImage containing the absolute file paths to the images.

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

References $i, ilShellUtil\escapeShellArg(), ilShellUtil\execQuoted(), ilPreviewRenderer\getMaximumNumberOfPreviews(), ilFileUtils\ilTempnam(), and ilFilePreviewRenderer\prepareFileForExec().

63  : array
64  {
65  $numOfPreviews = $this->getMaximumNumberOfPreviews();
66 
67  // get file path
68  $filepath = $obj->getFile();
69  $inputFile = $this->prepareFileForExec($filepath);
70 
71  // create a temporary file name and remove its extension
72  $output = str_replace(".tmp", "", ilFileUtils::ilTempnam());
73 
74  // use '#' instead of '%' as it gets replaced by 'escapeShellArg' on windows!
75  $outputFile = $output . "_#02d.png";
76 
77  // create images with ghostscript (we use PNG here as it has better transparency quality)
78  // gswin32c -dBATCH -dNOPAUSE -dSAFER -dFirstPage=1 -dLastPage=5 -sDEVICE=pngalpha -dEPSCrop -r72 -o $outputFile $inputFile
79  // gswin32c -dBATCH -dNOPAUSE -dSAFER -dFirstPage=1 -dLastPage=5 -sDEVICE=jpeg -dJPEGQ=90 -r72 -o $outputFile $inputFile
80  $args = sprintf(
81  "-dBATCH -dNOPAUSE -dSAFER -dFirstPage=1 -dLastPage=%d -sDEVICE=pngalpha -dEPSCrop -r72 -o %s %s",
82  $numOfPreviews,
83  str_replace("#", "%", ilShellUtil::escapeShellArg($outputFile)),
84  ilShellUtil::escapeShellArg($inputFile)
85  );
86 
87  ilShellUtil::execQuoted(PATH_TO_GHOSTSCRIPT, $args);
88 
89  // was a temporary file created? then delete it
90  if ($filepath !== $inputFile) {
91  @unlink($inputFile);
92  }
93 
94  // check each file and add it
95  $images = array();
96  $outputFile = str_replace("#", "%", $outputFile);
97 
98  for ($i = 1; $i <= $numOfPreviews; $i++) {
99  $imagePath = sprintf($outputFile, $i);
100  if (!file_exists($imagePath)) {
101  break;
102  }
103 
104  $images[] = new ilRenderedImage($imagePath);
105  }
106 
107  return $images;
108  }
getMaximumNumberOfPreviews()
Gets the maximum number of preview pictures per object.
static escapeShellArg(string $a_arg)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static execQuoted(string $cmd, ?string $args=null)
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
prepareFileForExec(string $filepath)
Checks whether the specified file path can be used with exec() commands.
$i
Definition: metadata.php:41
+ Here is the call graph for this function:

Field Documentation

◆ $supported_formats

array ilGhostscriptRenderer::$supported_formats = null
staticprivate

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

◆ SUPPORTED_FORMATS

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

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


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