* @property-read int $packageID id of the package which delivers the smiley
* @property-read int|null $categoryID id of the category the smiley belongs to or `null` if it belongs to the default category
* @property-read string $smileyPath path to the smiley file relative to wcf's default path
- * @property-read string $smileyPath2x path to the smiley file relative to wcf's default path (2x version)
+ * @property-read string $smileyPath2x path to the smiley file relative to wcf's default path (2x version)
* @property-read string $smileyTitle title of the smiley or name of language item that contains the title
* @property-read string $smileyCode code used for displaying the smiley
* @property-read string $aliases alternative codes used for displaying the smiley
{
protected $height;
+ protected $width;
+
public $smileyCodes;
/**
}
/**
- * Returns the height of the smiley.
+ * Returns the dimensions of the smiley.
*
- * @return int
+ * @since 5.4
+ * @return int[]
*/
- public function getHeight()
+ public function getDimensions()
{
if ($this->height === null) {
- $this->height = 0;
+ $this->height = $this->width = 0;
$file = WCF_DIR . $this->smileyPath;
if (\file_exists($file) && \preg_match('~\.(gif|jpe?g|png)$~', $file)) {
$data = \getimagesize($file);
if ($data !== false) {
- // index '1' contains the height of the image
- $this->height = $data[1];
+ // The first two indices of `getimagesize()` represent the image dimensions.
+ [$this->width, $this->height] = $data;
}
}
}
- return $this->height;
+ return [
+ 'width' => $this->width,
+ 'height' => $this->height,
+ ];
+ }
+
+ /**
+ * Returns the height of the smiley.
+ *
+ * @return int
+ */
+ public function getHeight()
+ {
+ return $this->getDimensions()['height'];
+ }
+
+ /**
+ * Returns the width of the smiley.
+ *
+ * @since 5.4
+ * @return int
+ */
+ public function getWidth()
+ {
+ return $this->getDimensions()['width'];
}
/**
{
$srcset = ($this->smileyPath2x) ? ' srcset="' . StringUtil::encodeHTML($this->getURL2x()) . ' 2x"' : '';
$height = ($this->getHeight()) ? ' height="' . $this->getHeight() . '"' : '';
+ $width = ($this->getWidth()) ? ' width="' . $this->getWidth() . '"' : '';
if ($class !== '') {
$class = ' ' . $class;
}
- return '<img src="' . StringUtil::encodeHTML($this->getURL()) . '" alt="' . StringUtil::encodeHTML($this->smileyCode) . '" title="' . WCF::getLanguage()->get($this->smileyTitle) . '" class="smiley' . $class . '"' . $srcset . $height . '>';
+ return '<img src="' . StringUtil::encodeHTML($this->getURL()) . '" alt="' . StringUtil::encodeHTML($this->smileyCode) . '" title="' . WCF::getLanguage()->get($this->smileyTitle) . '" class="smiley' . $class . '"' . $srcset . $height . $width . '>';
}
}