public function getDimensions()
{
if (!$this->width || !$this->height) {
$config = $this->getConfig();
$asset = $this->getAsset();
$dimensions = [];
// first we try to calculate the final dimensions based on the thumbnail configuration
if ($config) {
$dimensions = $config->getEstimatedDimensions($asset);
}
if (empty($dimensions)) {
// unable to calculate dimensions -> use fallback
// generate the thumbnail and get dimensions from the thumbnail file
$info = @getimagesize($this->getFileSystemPath());
if ($info) {
$dimensions = ["width" => $info[0], "height" => $info[1]];
}
}
$this->width = isset($dimensions["width"]) ? $dimensions["width"] : null;
$this->height = isset($dimensions["height"]) ? $dimensions["height"] : null;
// the following is only relevant if using high-res option (retina, ...)
$this->realHeight = $this->height;
$this->realWidth = $this->width;
if ($config && $config->getHighResolution() && $config->getHighResolution() > 1) {
$this->realWidth = floor($this->width * $config->getHighResolution());
$this->realHeight = floor($this->height * $config->getHighResolution());
}
}
return ["width" => $this->width, "height" => $this->height];
}