ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  if (strpos($name, "Renderer") === (strlen($name) - 8))
29  $name = substr($name, 0, strlen($name) - 8) . " Renderer";
30 
31  return $name;
32  }
33 
39  public final function isPlugin()
40  {
41  $filepath = "./Services/Preview/classes/class." . get_class($this) . ".php";
42  return !is_file($filepath);
43  }
44 
50  public abstract function getSupportedRepositoryTypes();
51 
58  public function supports($preview)
59  {
60  // contains type?
61  return in_array($preview->getObjType(), $this->getSupportedRepositoryTypes());
62  }
63 
72  public final function render($preview, $obj, $async)
73  {
74  $preview->setRenderDate(ilUtil::now());
76  $preview->save();
77 
78  // TODO: this should be done in background if $async is true
79 
80  // the deriving renderer should deliver images
81  require_once("./Services/Preview/classes/class.ilRenderedImage.php");
82  $images = $this->renderImages($obj);
83 
84  // process each image
85  if (is_array($images) && count($images) > 0)
86  {
87  $success = false;
88  foreach ($images as $idx => $image)
89  {
90  // create the ending preview image
91  $success |= $this->createPreviewImage(
92  $image->getImagePath(),
93  sprintf($preview->getFilePathFormat(), $idx + 1));
94 
95  // if the image is temporary we can delete it
96  if($image->isTemporary())
97  $image->delete();
98  }
99 
100  $preview->setRenderDate(ilUtil::now());
102  return $success;
103  }
104  else
105  {
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  ilUtil::execConvert($args);
134 
135  return is_file($dest_img_path);
136  }
137 
145  protected abstract function renderImages($obj);
146 
152  protected final function getImageSize()
153  {
155  }
156 
162  protected final function getImageQuality()
163  {
165  }
166 
172  protected final function getMaximumNumberOfPreviews()
173  {
175  }
176 }
177 ?>