ILIAS  release_8 Revision v8.24
class.ImageManager.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21namespace ILIAS\Style\Content;
22
25use ilShellUtil;
26use Generator;
27
33{
36 protected int $style_id;
37
38 public function __construct(
39 int $style_id,
42 ) {
43 $this->repo = $repo;
44 $this->access_manager = $access_manager;
45 $this->style_id = $style_id;
46 }
47
53 public function getImages(): Generator
54 {
55 return $this->repo->getImages($this->style_id);
56 }
57
58 public function filenameExists(string $filename): bool
59 {
61 foreach ($this->getImages() as $i) {
62 if ($i->getFilename() == $filename) {
63 return true;
64 }
65 }
66 return false;
67 }
68
69 // get web data dir path for output
70 public function getWebPath(Image $image): string
71 {
72 return $this->repo->getWebPath($image->getPath());
73 }
74
75 // get image data object by filename
76 public function getByFilename(string $filename): Image
77 {
78 return $this->repo->getByFilename($this->style_id, $filename);
79 }
80
81 // resize image
82 public function resizeImage(
83 string $filename,
84 int $width,
85 int $height,
86 bool $constrain_proportions
87 ): void {
88 if ($this->filenameExists($filename)) {
89 $file = $this->getWebPath($this->getByFilename($filename));
91 $file,
92 $file,
93 $width,
94 $height,
95 $constrain_proportions
96 );
97 }
98 }
99
100 // resize image
101 public function supportsResize(
102 Image $image
103 ): bool {
104 // for svg, see
105 // https://stackoverflow.com/questions/6532261/how-do-you-get-the-width-and-height-of-an-svg-picture-in-php
106 if (in_array(
107 strtolower(pathinfo($image->getFilename(), PATHINFO_EXTENSION)),
108 ["jpg", "jpeg", "gif", "png"]
109 )) {
110 return true;
111 }
112 return false;
113 }
114
115 // upload image
116 public function uploadImage(): void
117 {
118 $this->repo->uploadImage($this->style_id);
119 }
120
121 public function deleteByFilename(string $filename): void
122 {
123 $this->repo->deleteImageByFilename($this->style_id, $filename);
124 }
125}
$filename
Definition: buildRTE.php:78
Manages access to content style editing.
Main business logic for content style images.
Access StyleAccessManager $access_manager
resizeImage(string $filename, int $width, int $height, bool $constrain_proportions)
__construct(int $style_id, Access\StyleAccessManager $access_manager, ImageFileRepo $repo)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static resizeImage(string $a_from, string $a_to, int $a_width, int $a_height, bool $a_constrain_prop=false)
resize image
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
$i
Definition: metadata.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...