ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ILIAS\MediaObjects\Thumbs\ThumbsManager Class Reference
+ Collaboration diagram for ILIAS\MediaObjects\Thumbs\ThumbsManager:

Public Member Functions

 __construct (protected InternalDataService $data, InternalRepoService $repo, protected InternalDomainService $domain)
 
 getThumbSrc (int $mob_id)
 For use in browser src of images. More...
 
 createPreview (int $mob_id, string $location, bool $local, string $format, int $sec=1, string $target_location="mob_vpreview.png")
 
 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,)
 
 resizeToFixedSize (Stream $stream, int $width, int $height, bool $crop_if_true_and_resize_if_false, ImageOutputOptions $output_options)
 

Protected Attributes

ILIAS MediaObjects MediaObjectRepository $repo
 
ILIAS MediaObjects MediaObjectManager $media_manager
 
ImageOutputOptions $output_options
 
Images $image_converters
 

Detailed Description

Definition at line 33 of file ThumbsManager.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 40 of file ThumbsManager.php.

44 {
45 $this->media_manager = $this->domain->mediaObject();
46 $this->image_converters = new Images(true);
47 $this->output_options = new ImageOutputOptions();
48 $this->repo = $repo->mediaObject();
49 }
ILIAS MediaObjects MediaObjectRepository $repo

References ILIAS\MediaObjects\Thumbs\ThumbsManager\$repo.

Member Function Documentation

◆ createPreview()

ILIAS\MediaObjects\Thumbs\ThumbsManager::createPreview ( int  $mob_id,
string  $location,
bool  $local,
string  $format,
int  $sec = 1,
string  $target_location = "mob_vpreview.png" 
)

Definition at line 143 of file ThumbsManager.php.

150 : void {
151
152 $is_image = is_int(strpos($format, "image/"));
153 $is_video = in_array($format, ["video/mp4", "video/webm"]);
154
155 if ($local) {
156 if ($is_image) {
158 $image_quality = 60;
159
160 // the zip stream is not seekable, which is needed by Imagick
161 // so we create a seekable stream first
162 $tempStream = fopen('php://temp', 'w+');
163 stream_copy_to_stream($this->repo->getLocationStream($mob_id, $location)->detach(), $tempStream);
164 rewind($tempStream);
165 $stream = new Stream($tempStream);
166
167 $converter = $this->resizeToFixedSize(
168 $stream,
169 $width,
170 $height,
171 true,
172 $this->output_options
173 ->withQuality($image_quality)
175 );
176 $this->repo->addStream(
177 $mob_id,
178 $target_location,
179 $converter->getStream()
180 );
181 fclose($tempStream);
182 }
183 if ($is_video) {
184 $zip_uri = $this->repo->getContainerPath($mob_id);
186 $zip_uri,
187 $location,
188 $sec
189 );
190 $png_res = fopen('php://memory', 'r+');
191 fwrite($png_res, $image_str);
192 rewind($png_res);
193 $png_stream = new Stream($png_res);
194 $this->repo->addStream(
195 $mob_id,
196 $target_location,
197 $png_stream
198 );
199 }
200 }
201 }
$location
Definition: buildRTE.php:22
resizeToFixedSize(Stream $stream, int $width, int $height, bool $crop_if_true_and_resize_if_false, ImageOutputOptions $output_options)
static extractPNGFromVideoInZip(string $zip, string $path, int $sec=1)

◆ createThumb()

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

Definition at line 104 of file ThumbsManager.php.

109 : void {
110 $is_image = is_int(strpos($format, "image/"));
111 if ($is_image) {
112 if (!$this->media_manager->hasLocalFile($mob_id, $location)) {
113 return;
114 }
115 $width = $height = \ilObjMediaObject::DEFAULT_THUMB_SIZE;
116 $image_quality = 90;
117
118 // the zip stream is not seekable, which is needed by Imagick
119 // so we create a seekable stream first
120 $tempStream = fopen('php://temp', 'w+');
121 stream_copy_to_stream($this->media_manager->getLocationStream($mob_id, $location)->detach(), $tempStream);
122 rewind($tempStream);
123 $stream = new Stream($tempStream);
124
125 $converter = $this->resizeToFixedSize(
126 $stream,
127 $width,
128 $height,
129 true,
130 $this->output_options
131 ->withQuality($image_quality)
133 );
134 $this->media_manager->addStream(
135 $mob_id,
136 $target_location,
137 $converter->getStream()
138 );
139 fclose($tempStream);
140 }
141 }

References $location, ilObjMediaObject\DEFAULT_THUMB_SIZE, ILIAS\Filesystem\Util\Convert\ImageOutputOptions\FORMAT_PNG, and ILIAS\MediaObjects\Thumbs\ThumbsManager\resizeToFixedSize().

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

+ Here is the call graph for this function:
+ 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 231 of file ThumbsManager.php.

231 : string
232 {
233 $ppics = array(
234 "mob_vpreview.png",
235 "mob_vpreview.jpg",
236 "mob_vpreview.jpeg");
237 foreach ($ppics as $pic) {
238 if ($this->media_manager->hasLocalFile($mob_id, $pic)) {
239 return $this->media_manager->getLocalSrc($mob_id, $pic);
240 }
241 }
242 return "";
243 }

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

+ Here is the caller graph for this function:

◆ getThumbPath()

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

Definition at line 51 of file ThumbsManager.php.

51 : string
52 {
53 return "thumbs/Standard.png";
54 }

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

+ 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 59 of file ThumbsManager.php.

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

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

+ Here is the call graph for this function:

◆ resizeToFixedSize()

ILIAS\MediaObjects\Thumbs\ThumbsManager::resizeToFixedSize ( Stream  $stream,
int  $width,
int  $height,
bool  $crop_if_true_and_resize_if_false,
ImageOutputOptions  $output_options 
)
protected

Definition at line 204 of file ThumbsManager.php.

210 : ImageConverter {
211 $conversion_options = (new ImageConversionOptions())
212 ->withMakeTemporaryFiles(false)
213 ->withThrowOnError(false)
214 ->withBackgroundColor('#FFFFFF');
215
216 return new ImageConverter(
217 $conversion_options
218 ->withWidth($width)
219 ->withHeight($height)
220 ->withCrop($crop_if_true_and_resize_if_false)
221 ->withKeepAspectRatio(true),
223 $stream
224 );
225 }

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

+ Here is the caller graph for this function:

Field Documentation

◆ $image_converters

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

Definition at line 38 of file ThumbsManager.php.

◆ $media_manager

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

Definition at line 36 of file ThumbsManager.php.

◆ $output_options

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

Definition at line 37 of file ThumbsManager.php.

◆ $repo

ILIAS MediaObjects MediaObjectRepository ILIAS\MediaObjects\Thumbs\ThumbsManager::$repo
protected

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