ILIAS  release_8 Revision v8.24
class.ilPreviewRenderer.php
Go to the documentation of this file.
1<?php
26abstract class ilPreviewRenderer
27{
33 public function getName(): string
34 {
35 $name = get_class($this);
36
37 if (strpos($name, "il") === 0) {
38 $name = substr($name, 2);
39 }
40
41 if (strpos($name, "Renderer") === (strlen($name) - 8)) {
42 $name = substr($name, 0, -8) . " Renderer";
43 }
44
45 return $name;
46 }
47
53 final public function isPlugin(): bool
54 {
55 return !is_file("./Services/Preview/classes/class." . get_class($this) . ".php");
56 }
57
63 abstract public function getSupportedRepositoryTypes(): array;
64
71 public function supports(\ilPreview $preview): bool
72 {
73 // contains type?
74 return in_array($preview->getObjType(), $this->getSupportedRepositoryTypes());
75 }
76
85 final public function render(\ilPreview $preview, \ilObject $obj, bool $async): ?bool
86 {
87 $preview->setRenderDate(ilUtil::now());
89 $preview->save();
90 $images = $this->renderImages($obj);
91
92 // process each image
93 if (is_array($images) && count($images) > 0) {
94 $success = false;
95 foreach ($images as $idx => $image) {
96 // create the ending preview image
97 $success |= $this->createPreviewImage(
98 $image->getImagePath(),
99 sprintf($preview->getFilePathFormat(), $idx + 1)
100 );
101
102 // if the image is temporary we can delete it
103 if ($image->isTemporary()) {
104 $image->delete();
105 }
106 }
107
108 $preview->setRenderDate(ilUtil::now());
110 return $success;
111 }
112
113 $preview->setRenderDate(ilUtil::now());
115 return false;
116 }
117
125 private function createPreviewImage(string $src_img_path, string $dest_img_path): bool
126 {
127 // create resize argument
128 $imgSize = $this->getImageSize();
129 $resizeArg = $imgSize . "x" . $imgSize . (ilUtil::isWindows() ? "^" : "\\") . ">";
130
131 // cmd: convert $src_img_path -background white -flatten -resize 280x280 -quality 85 -sharpen 0x0.5 $dest_img_path
132 $args = sprintf(
133 "%s -background white -flatten -resize %s -quality %d -sharpen 0x0.5 %s",
134 ilShellUtil::escapeShellArg($src_img_path),
135 $resizeArg,
136 $this->getImageQuality(),
137 ilShellUtil::escapeShellArg($dest_img_path)
138 );
139
140 ilShellUtil::execQuoted(PATH_TO_CONVERT, $args);
141
142 return is_file($dest_img_path);
143 }
144
152 abstract protected function renderImages(\ilObject $obj): array;
153
159 final protected function getImageSize(): int
160 {
162 }
163
169 final protected function getImageQuality(): int
170 {
172 }
173
179 final protected function getMaximumNumberOfPreviews(): int
180 {
182 }
183}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
renderImages(\ilObject $obj)
Renders the specified object into images.
supports(\ilPreview $preview)
Determines whether the specified preview object is supported by the renderer.
getImageQuality()
Gets the quality (compression) of the preview images (1-100).
getName()
Gets the name of the renderer.
getSupportedRepositoryTypes()
Gets an array containing the repository types (e.g.
render(\ilPreview $preview, \ilObject $obj, bool $async)
Creates the preview of the specified preview object.
createPreviewImage(string $src_img_path, string $dest_img_path)
Creates a preview image path from the specified source image.
getMaximumNumberOfPreviews()
Gets the maximum number of preview pictures per object.
isPlugin()
Determines whether the renderer is a plugin or a built in one.
getImageSize()
Gets the size of the preview images in pixels.
static getImageSize()
Gets the size of the preview images in pixels.
static getMaximumPreviews()
Gets the maximum number of preview pictures per object.
static getImageQuality()
Gets the quality (compression) of the preview images (1-100).
const RENDER_STATUS_FAILED
const RENDER_STATUS_CREATED
const RENDER_STATUS_PENDING
static escapeShellArg(string $a_arg)
static execQuoted(string $cmd, ?string $args=null)
static isWindows()
static now()
Return current timestamp in Y-m-d H:i:s format.
$preview
Definition: imgupload.php:81
if($format !==null) $name
Definition: metadata.php:247