ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ILIAS\MediaObjects\Thumbs\ThumbsManager Class Reference
+ Collaboration diagram for ILIAS\MediaObjects\Thumbs\ThumbsManager:

Public Member Functions

 __construct (protected InternalDataService $data, protected InternalDomainService $domain)
 
 getThumbSrc (int $mob_id)
 For use in browser src of images. More...
 
 getPreviewSrc (int $mob_id)
 For use in browser src of images. More...
 

Protected Member Functions

 getThumbPath ()
 
 createThumb (int $mob_id, string $location, string $format, string $target_location,)
 

Protected Attributes

ILIAS MediaObjects MediaObjectManager $media_manager
 
ImageOutputOptions $output_options
 
Images $image_converters
 

Detailed Description

Definition at line 31 of file ThumbsManager.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\MediaObjects\Thumbs\ThumbsManager::__construct ( protected InternalDataService  $data,
protected InternalDomainService  $domain 
)

Definition at line 38 of file ThumbsManager.php.

41  {
42  $this->media_manager = $this->domain->mediaObject();
43  $this->image_converters = new Images(true);
44  $this->output_options = new ImageOutputOptions();
45  }

Member Function Documentation

◆ createThumb()

ILIAS\MediaObjects\Thumbs\ThumbsManager::createThumb ( int  $mob_id,
string  $location,
string  $format,
string  $target_location 
)
protected

Definition at line 100 of file ThumbsManager.php.

References ilObjMediaObject\DEFAULT_PREVIEW_SIZE, and ILIAS\Filesystem\Util\Convert\ImageOutputOptions\FORMAT_PNG.

Referenced by ILIAS\MediaObjects\Thumbs\ThumbsManager\getThumbSrc().

105  : void
106  {
107  $is_image = is_int(strpos($format, "image/"));
108  if ($is_image) {
109  if (!$this->media_manager->hasLocalFile($mob_id, $location)) {
110  return;
111  }
112  $width = $height = \ilObjMediaObject::DEFAULT_PREVIEW_SIZE;
113  $image_quality = 90;
114 
115  // the zip stream is not seekable, which is needed by Imagick
116  // so we create a seekable stream first
117  $tempStream = fopen('php://temp', 'w+');
118  stream_copy_to_stream($this->media_manager->getLocationStream($mob_id, $location)->detach(), $tempStream);
119  rewind($tempStream);
120  $stream = new Stream($tempStream);
121 
122  $converter = $this->image_converters->resizeToFixedSize(
123  $stream,
124  $width,
125  $height,
126  true,
127  $this->output_options
128  ->withQuality($image_quality)
129  ->withFormat(ImageOutputOptions::FORMAT_PNG)
130  );
131  $this->media_manager->addStream(
132  $mob_id,
133  $target_location,
134  $converter->getStream()
135  );
136  fclose($tempStream);
137  }
138  }
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
+ Here is the caller graph for this function:

◆ getPreviewSrc()

ILIAS\MediaObjects\Thumbs\ThumbsManager::getPreviewSrc ( int  $mob_id)

For use in browser src of images.

Definition at line 143 of file ThumbsManager.php.

Referenced by ILIAS\MediaObjects\Thumbs\ThumbsManager\getThumbSrc().

143  : string
144  {
145  $ppics = array(
146  "mob_vpreview.png",
147  "mob_vpreview.jpg",
148  "mob_vpreview.jpeg");
149  foreach ($ppics as $pic) {
150  if ($this->media_manager->hasLocalFile($mob_id, $pic)) {
151  return $this->media_manager->getLocalSrc($mob_id, $pic);
152  }
153  }
154  return "";
155  }
+ Here is the caller graph for this function:

◆ getThumbPath()

ILIAS\MediaObjects\Thumbs\ThumbsManager::getThumbPath ( )
protected

Definition at line 47 of file ThumbsManager.php.

Referenced by ILIAS\MediaObjects\Thumbs\ThumbsManager\getThumbSrc().

47  : string
48  {
49  return "thumbs/Standard.png";
50  }
+ Here is the caller graph for this function:

◆ getThumbSrc()

ILIAS\MediaObjects\Thumbs\ThumbsManager::getThumbSrc ( int  $mob_id)

For use in browser src of images.

Definition at line 55 of file ThumbsManager.php.

References ILIAS\MediaObjects\Thumbs\ThumbsManager\createThumb(), ILIAS\MediaObjects\Thumbs\ThumbsManager\getPreviewSrc(), and ILIAS\MediaObjects\Thumbs\ThumbsManager\getThumbPath().

55  : string
56  {
57  $mob = new \ilObjMediaObject($mob_id);
58  $item = $mob->getMediaItem("Standard");
59  // for svg return standard src
60  if ($item?->getFormat() === "image/svg+xml") {
61  return $mob->getStandardSrc();
62  }
63 
64  // if thumb exists -> return
65  $thumb_path = $this->getThumbPath();
66  if ($this->media_manager->hasLocalFile($mob_id, $thumb_path)) {
67  return $this->media_manager->getLocalSrc($mob_id, $thumb_path);
68  }
69 
70  // if preview exists -> return
71  $preview_src = $this->getPreviewSrc($mob_id);
72  if ($preview_src !== "") {
73  return $preview_src;
74  }
75 
76  // if not tried already, create thumb and return
77  if ($item?->getLocationType() === "LocalFile") {
78  if ($item?->getThumbTried() !== "y") {
79  $this->createThumb(
80  $mob_id,
81  $item?->getLocation(),
82  $item?->getFormat(),
83  $thumb_path
84  );
85  $item?->writeThumbTried("y");
86  if ($this->media_manager->hasLocalFile($mob_id, $thumb_path)) {
87  return $this->media_manager->getLocalSrc($mob_id, $thumb_path);
88  }
89  }
90  } else {
91  if (str_starts_with($item?->getFormat(), "image/")) {
92  return $item?->getLocation();
93  }
94  }
95 
96  // send generic thumb src
97  return \ilUtil::getImagePath("standard/icon_mob.svg");
98  }
getPreviewSrc(int $mob_id)
For use in browser src of images.
createThumb(int $mob_id, string $location, string $format, string $target_location,)
+ Here is the call graph for this function:

Field Documentation

◆ $image_converters

Images ILIAS\MediaObjects\Thumbs\ThumbsManager::$image_converters
protected

Definition at line 36 of file ThumbsManager.php.

◆ $media_manager

ILIAS MediaObjects MediaObjectManager ILIAS\MediaObjects\Thumbs\ThumbsManager::$media_manager
protected

Definition at line 34 of file ThumbsManager.php.

◆ $output_options

ImageOutputOptions ILIAS\MediaObjects\Thumbs\ThumbsManager::$output_options
protected

Definition at line 35 of file ThumbsManager.php.


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