ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilPreviewRenderer Class Reference

Abstract parent class for all preview renderer classes. More...

+ Inheritance diagram for ilPreviewRenderer:
+ Collaboration diagram for ilPreviewRenderer:

Public Member Functions

 getName ()
 Gets the name of the renderer. More...
 
 isPlugin ()
 Determines whether the renderer is a plugin or a built in one. More...
 
 getSupportedRepositoryTypes ()
 Gets an array containing the repository types (e.g. More...
 
 supports ($preview)
 Determines whether the specified preview object is supported by the renderer. More...
 
 render ($preview, $obj, $async)
 Creates the preview of the specified preview object. More...
 

Protected Member Functions

 renderImages ($obj)
 Renders the specified object into images. More...
 
 getImageSize ()
 Gets the size of the preview images in pixels. More...
 
 getImageQuality ()
 Gets the quality (compression) of the preview images (1-100). More...
 
 getMaximumNumberOfPreviews ()
 Gets the maximum number of preview pictures per object. More...
 

Private Member Functions

 createPreviewImage ($src_img_path, $dest_img_path)
 Creates a preview image path from the specified source image. More...
 

Detailed Description

Abstract parent class for all preview renderer classes.

Author
Stefan Born stefa.nosp@m.n.bo.nosp@m.rn@ph.nosp@m.zh.c.nosp@m.h
Version
$Id$

Definition at line 14 of file class.ilPreviewRenderer.php.

Member Function Documentation

◆ createPreviewImage()

ilPreviewRenderer::createPreviewImage (   $src_img_path,
  $dest_img_path 
)
private

Creates a preview image path from the specified source image.

Parameters
string$src_img_pathThe source image path.
string$dest_img_pathThe destination image path.
Returns
bool true, if the preview was created; otherwise, false.

Definition at line 119 of file class.ilPreviewRenderer.php.

References ilUtil\escapeShellArg(), ilUtil\execQuoted(), getImageQuality(), getImageSize(), ilUtil\isWindows(), and renderImages().

Referenced by render().

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  }
static isWindows()
check wether the current client system is a windows system
static execQuoted($cmd, $args=null)
exec command and fix spaces on windows
static escapeShellArg($a_arg)
getImageSize()
Gets the size of the preview images in pixels.
getImageQuality()
Gets the quality (compression) of the preview images (1-100).
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImageQuality()

ilPreviewRenderer::getImageQuality ( )
finalprotected

Gets the quality (compression) of the preview images (1-100).

Returns
int The current value

Definition at line 163 of file class.ilPreviewRenderer.php.

References ilPreviewSettings\getImageQuality().

Referenced by createPreviewImage().

164  {
166  }
static getImageQuality()
Gets the quality (compression) of the preview images (1-100).
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImageSize()

ilPreviewRenderer::getImageSize ( )
finalprotected

Gets the size of the preview images in pixels.

Returns
int The current value

Definition at line 153 of file class.ilPreviewRenderer.php.

References ilPreviewSettings\getImageSize().

Referenced by createPreviewImage().

154  {
156  }
static getImageSize()
Gets the size of the preview images in pixels.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMaximumNumberOfPreviews()

ilPreviewRenderer::getMaximumNumberOfPreviews ( )
finalprotected

Gets the maximum number of preview pictures per object.

Returns
int The current value

Definition at line 173 of file class.ilPreviewRenderer.php.

References ilPreviewSettings\getMaximumPreviews().

Referenced by ilGhostscriptRenderer\renderImages().

174  {
176  }
static getMaximumPreviews()
Gets the maximum number of preview pictures per object.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getName()

ilPreviewRenderer::getName ( )

Gets the name of the renderer.

Returns
string The name of the renderer.

Definition at line 21 of file class.ilPreviewRenderer.php.

References $name.

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  }

◆ getSupportedRepositoryTypes()

ilPreviewRenderer::getSupportedRepositoryTypes ( )
abstract

Gets an array containing the repository types (e.g.

'file' or 'crs') that are supported by the renderer.

Returns
array An array containing the supported repository types.

Referenced by isPlugin(), and supports().

+ Here is the caller graph for this function:

◆ isPlugin()

ilPreviewRenderer::isPlugin ( )
final

Determines whether the renderer is a plugin or a built in one.

Returns
bool true, if the renderer is a plugin; otherwise, false.

Definition at line 41 of file class.ilPreviewRenderer.php.

References getSupportedRepositoryTypes().

42  {
43  $filepath = "./Services/Preview/classes/class." . get_class($this) . ".php";
44  return !is_file($filepath);
45  }
+ Here is the call graph for this function:

◆ render()

ilPreviewRenderer::render (   $preview,
  $obj,
  $async 
)
final

Creates the preview of the specified preview object.

Parameters
ilPreview$previewThe preview object.
ilObject$objThe object to create a preview for.
bool$asynctrue, if the rendering should be done asynchronously; otherwise, false.
Returns
bool true, if the preview was successfully rendered; otherwise, false.

Definition at line 74 of file class.ilPreviewRenderer.php.

References $preview, $success, createPreviewImage(), ilUtil\now(), ilPreview\RENDER_STATUS_CREATED, ilPreview\RENDER_STATUS_FAILED, ilPreview\RENDER_STATUS_PENDING, and renderImages().

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  }
createPreviewImage($src_img_path, $dest_img_path)
Creates a preview image path from the specified source image.
$preview
const RENDER_STATUS_FAILED
const RENDER_STATUS_PENDING
static now()
Return current timestamp in Y-m-d H:i:s format.
$success
Definition: Utf8Test.php:86
const RENDER_STATUS_CREATED
renderImages($obj)
Renders the specified object into images.
+ Here is the call graph for this function:

◆ renderImages()

ilPreviewRenderer::renderImages (   $obj)
abstractprotected

Renders the specified object into images.

The images do not need to be of the preview image size.

Parameters
ilObject$objThe object to create images from.
Returns
array An array of ilRenderedImage containing the absolute file paths to the images.

Referenced by createPreviewImage(), and render().

+ Here is the caller graph for this function:

◆ supports()

ilPreviewRenderer::supports (   $preview)

Determines whether the specified preview object is supported by the renderer.

Parameters
ilPreview$previewThe preview object to check.
Returns
bool true, if the renderer supports the specified preview object; otherwise, false.

Definition at line 60 of file class.ilPreviewRenderer.php.

References $preview, and getSupportedRepositoryTypes().

61  {
62  // contains type?
63  return in_array($preview->getObjType(), $this->getSupportedRepositoryTypes());
64  }
$preview
getSupportedRepositoryTypes()
Gets an array containing the repository types (e.g.
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: