ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilGhostscriptRenderer.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Preview/classes/class.ilFilePreviewRenderer.php");
5 
15 {
16  // constants
17  const SUPPORTED_FORMATS = "eps,pdf,pdfa,ps";
18 
19  // variables
20  private static $supported_formats = null;
21 
27  public function getSupportedFileFormats()
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  }
36 
40  public static function isGhostscriptInstalled()
41  {
42  return (PATH_TO_GHOSTSCRIPT != "");
43  }
44 
52  protected function renderImages($obj)
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  }
98 }
prepareFileForExec($filepath)
Checks whether the specified file path can be used with exec() commands.
getMaximumNumberOfPreviews()
Gets the maximum number of preview pictures per object.
Abstract parent class for all file preview renderer classes.
static isGhostscriptInstalled()
Determines whether Ghostscript is installed.
renderImages($obj)
Renders the specified object into images.
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.
getSupportedFileFormats()
Gets an array containing the file formats that are supported by the renderer.
static escapeShellArg($a_arg)
$i
Definition: disco.tpl.php:19
Preview renderer class that is able to create previews from PDF, PS and EPS by using GhostScript...