ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
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 ?>