ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 30 of file ThumbsManager.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 36 of file ThumbsManager.php.

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

Member Function Documentation

◆ createThumb()

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

Definition at line 98 of file ThumbsManager.php.

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

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

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

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

140 : string
141 {
142 $ppics = array(
143 "mob_vpreview.png",
144 "mob_vpreview.jpg",
145 "mob_vpreview.jpeg");
146 foreach ($ppics as $pic) {
147 if ($this->media_manager->hasLocalFile($mob_id, $pic)) {
148 return $this->media_manager->getLocalSrc($mob_id, $pic);
149 }
150 }
151 return "";
152 }

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

45 : string
46 {
47 return "thumbs/Standard.png";
48 }

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

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

Field Documentation

◆ $image_converters

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

Definition at line 34 of file ThumbsManager.php.

◆ $media_manager

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

Definition at line 32 of file ThumbsManager.php.

◆ $output_options

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

Definition at line 33 of file ThumbsManager.php.


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