ILIAS  release_8 Revision v8.24
Image.php
Go to the documentation of this file.
1<?php
2
20
28class Image
29{
35 private ?string $url = null;
36
42 private ?int $width = null;
43
49 private ?int $height = null;
50
57 public function __construct(string $url, int $width = null, int $height = null)
58 {
59 $this->url = $url;
60 $this->height = $height;
61 $this->width = $width;
62 }
63
69 public function toJsonldObject(): object
70 {
71 $image = new \stdClass();
72 $image->{'@id'} = $this->url;
73 if (!is_null($this->width)) {
74 $image->width = $this->width;
75 }
76 if (!is_null($this->height)) {
77 $image->height = $this->height;
78 }
79
80 return $image;
81 }
82
88 public function toJsonObject(): string
89 {
90 $image = new \stdClass();
91 $image->url = $this->url;
92 if (!is_null($this->width)) {
93 $image->width = $this->width;
94 }
95 if (!is_null($this->height)) {
96 $image->height = $this->height;
97 }
98
99 return $image;
100 }
101
107 public static function fromJsonObject(object $item): ?Image
108 {
109 $obj = null;
110 $width = null;
111 $height = null;
112 if (is_object($item)) {
113 $url = null;
114 foreach (get_object_vars($item) as $name => $value) {
115 switch ($name) {
116 case '@id':
117 case 'url':
118 $url = $item->{$name};
119 break;
120 case 'width':
121 $width = $item->width;
122 break;
123 case 'height':
124 $height = $item->height;
125 break;
126 }
127 }
128 } else {
129 $url = $item;
130 }
131 if ($url) {
132 $obj = new Image($url, $height, $width);
133 }
134
135 return $obj;
136 }
137}
Class to represent a content-item image object.
Definition: Image.php:29
__construct(string $url, int $width=null, int $height=null)
Class constructor.
Definition: Image.php:57
toJsonldObject()
Generate the JSON-LD object representation of the image.
Definition: Image.php:69
int $width
Width of image.
Definition: Image.php:42
toJsonObject()
Generate the JSON object representation of the image.
Definition: Image.php:88
static fromJsonObject(object $item)
Generate an Image object from its JSON or JSON-LD representation.
Definition: Image.php:107
string $url
URL of image.
Definition: Image.php:35
int $height
Height of image.
Definition: Image.php:49
if($format !==null) $name
Definition: metadata.php:247
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: FileItem.php:19
$url