ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
4include_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?>
Abstract parent class for all file preview renderer classes.
prepareFileForExec($filepath)
Checks whether the specified file path can be used with exec() commands.
Preview renderer class that is able to create previews from PDF, PS and EPS by using GhostScript.
getSupportedFileFormats()
Gets an array containing the file formats that are supported by the renderer.
static isGhostscriptInstalled()
Determines whether Ghostscript is installed.
renderImages($obj)
Renders the specified object into images.
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 escapeShellArg($a_arg)
static execQuoted($cmd, $args=NULL)
exec command and fix spaces on windows
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.