ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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.

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 }
getImageQuality()
Gets the quality (compression) of the preview images (1-100).
getImageSize()
Gets the size of the preview images in pixels.
static escapeShellArg($a_arg)
static execConvert($args)
execute convert command
static isWindows()
check wether the current client system is a windows system

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

Referenced by render().

+ 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 162 of file class.ilPreviewRenderer.php.

163 {
165 }
static getImageQuality()
Gets the quality (compression) of the preview images (1-100).

References ilPreviewSettings\getImageQuality().

Referenced by createPreviewImage().

+ 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 152 of file class.ilPreviewRenderer.php.

153 {
155 }
static getImageSize()
Gets the size of the preview images in pixels.

References ilPreviewSettings\getImageSize().

Referenced by createPreviewImage().

+ 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 172 of file class.ilPreviewRenderer.php.

173 {
175 }
static getMaximumPreviews()
Gets the maximum number of preview pictures per object.

References ilPreviewSettings\getMaximumPreviews().

Referenced by ilGhostscriptRenderer\renderImages().

+ 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.

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 }

◆ 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.

Reimplemented in ilFilePreviewRenderer.

◆ 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 39 of file class.ilPreviewRenderer.php.

40 {
41 $filepath = "./Services/Preview/classes/class." . get_class($this) . ".php";
42 return !is_file($filepath);
43 }

◆ 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 72 of file class.ilPreviewRenderer.php.

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
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());
108 return false;
109 }
110 }
$success
Definition: Utf8Test.php:87
renderImages($obj)
Renders the specified object into images.
createPreviewImage($src_img_path, $dest_img_path)
Creates a preview image path from the specified source image.
const RENDER_STATUS_FAILED
const RENDER_STATUS_CREATED
const RENDER_STATUS_PENDING
static now()
Return current timestamp in Y-m-d H:i:s format.
$preview

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

+ 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.

Reimplemented in ilGhostscriptRenderer, and ilImageMagickRenderer.

Referenced by 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.

Reimplemented in ilFilePreviewRenderer.

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

59 {
60 // contains type?
61 return in_array($preview->getObjType(), $this->getSupportedRepositoryTypes());
62 }

References $preview.


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