ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilPreviewRenderer.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once("./Services/Preview/classes/class.ilPreviewSettings.php");
5 
14 abstract class ilPreviewRenderer
15 {
21  public function getName()
22  {
23  $name = get_class($this);
24 
25  if (strpos($name, "il") === 0) {
26  $name = substr($name, 2);
27  }
28 
29  if (strpos($name, "Renderer") === (strlen($name) - 8)) {
30  $name = substr($name, 0, strlen($name) - 8) . " Renderer";
31  }
32 
33  return $name;
34  }
35 
41  final public function isPlugin()
42  {
43  $filepath = "./Services/Preview/classes/class." . get_class($this) . ".php";
44  return !is_file($filepath);
45  }
46 
52  abstract public function getSupportedRepositoryTypes();
53 
60  public function supports($preview)
61  {
62  // contains type?
63  return in_array($preview->getObjType(), $this->getSupportedRepositoryTypes());
64  }
65 
74  final public function render($preview, $obj, $async)
75  {
76  $preview->setRenderDate(ilUtil::now());
78  $preview->save();
79 
80  // TODO: this should be done in background if $async is true
81 
82  // the deriving renderer should deliver images
83  require_once("./Services/Preview/classes/class.ilRenderedImage.php");
84  $images = $this->renderImages($obj);
85 
86  // process each image
87  if (is_array($images) && count($images) > 0) {
88  $success = false;
89  foreach ($images as $idx => $image) {
90  // create the ending preview image
91  $success |= $this->createPreviewImage(
92  $image->getImagePath(),
93  sprintf($preview->getFilePathFormat(), $idx + 1)
94  );
95 
96  // if the image is temporary we can delete it
97  if ($image->isTemporary()) {
98  $image->delete();
99  }
100  }
101 
102  $preview->setRenderDate(ilUtil::now());
104  return $success;
105  } else {
106  $preview->setRenderDate(ilUtil::now());
107  $preview->setRenderStatus(ilPreview::RENDER_STATUS_FAILED);
108  return false;
109  }
110  }
111 
119  private function createPreviewImage($src_img_path, $dest_img_path)
120  {
121  // create resize argument
122  $imgSize = $this->getImageSize();
123  $resizeArg = $imgSize . "x" . $imgSize . (ilUtil::isWindows() ? "^" : "\\") . ">";
124 
125  // cmd: convert $src_img_path -background white -flatten -resize 280x280 -quality 85 -sharpen 0x0.5 $dest_img_path
126  $args = sprintf(
127  "%s -background white -flatten -resize %s -quality %d -sharpen 0x0.5 %s",
128  ilUtil::escapeShellArg($src_img_path),
129  $resizeArg,
130  $this->getImageQuality(),
131  ilUtil::escapeShellArg($dest_img_path)
132  );
133 
134  ilUtil::execQuoted(PATH_TO_CONVERT, $args);
135 
136  return is_file($dest_img_path);
137  }
138 
146  abstract protected function renderImages($obj);
147 
153  final protected function getImageSize()
154  {
156  }
157 
163  final protected function getImageQuality()
164  {
166  }
167 
173  final protected function getMaximumNumberOfPreviews()
174  {
176  }
177 }
getMaximumNumberOfPreviews()
Gets the maximum number of preview pictures per object.
static getImageQuality()
Gets the quality (compression) of the preview images (1-100).
createPreviewImage($src_img_path, $dest_img_path)
Creates a preview image path from the specified source image.
getName()
Gets the name of the renderer.
$preview
const RENDER_STATUS_FAILED
isPlugin()
Determines whether the renderer is a plugin or a built in one.
Abstract parent class for all preview renderer classes.
const RENDER_STATUS_PENDING
static now()
Return current timestamp in Y-m-d H:i:s format.
static isWindows()
check wether the current client system is a windows system
render($preview, $obj, $async)
Creates the preview of the specified preview object.
$success
Definition: Utf8Test.php:86
supports($preview)
Determines whether the specified preview object is supported by the renderer.
static getMaximumPreviews()
Gets the maximum number of preview pictures per object.
const RENDER_STATUS_CREATED
static execQuoted($cmd, $args=null)
exec command and fix spaces on windows
static getImageSize()
Gets the size of the preview images in pixels.
static escapeShellArg($a_arg)
getSupportedRepositoryTypes()
Gets an array containing the repository types (e.g.
getImageSize()
Gets the size of the preview images in pixels.
renderImages($obj)
Renders the specified object into images.
getImageQuality()
Gets the quality (compression) of the preview images (1-100).