ILIAS  release_7 Revision v7.30-3-g800a261c036
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 }
33
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}
An exception for terminatinating execution or to throw for unit testing.
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 execQuoted($cmd, $args=null)
exec command and fix spaces on windows
static escapeShellArg($a_arg)
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
$i
Definition: metadata.php:24