ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  return self::$supported_formats;
34  }
35 
39  public static function isGhostscriptInstalled()
40  {
41  return (PATH_TO_GHOSTSCRIPT != "");
42  }
43 
51  protected function renderImages($obj)
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  }
95 }
96 ?>
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.
static execQuoted($cmd, $args=NULL)
exec command and fix spaces on windows
renderImages($obj)
Renders the specified object into images.
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
Represents an image that was created from a preview renderer and that can be further processed to cre...
Create styles array
The data for the language used.
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.
getSupportedFileFormats()
Gets an array containing the file formats that are supported by the renderer.
static escapeShellArg($a_arg)
Preview renderer class that is able to create previews from PDF, PS and EPS by using GhostScript...