Skip to content

Commit 8b1951f

Browse files
authored
Added getWidthAndHeigth function to image helper
1 parent 6c06635 commit 8b1951f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Helper/Image.php

+24
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,30 @@ public function resize($width, $height = null, $keepFrame = null)
126126
return $this;
127127
}
128128

129+
/**
130+
* @return array
131+
*/
132+
public function getWidthAndHeigth(): array
133+
{
134+
$file = $this->_newFile ?: $this->_baseFile;
135+
if (!$file) {
136+
return [];
137+
}
138+
139+
if ($this->fileExists($file)) {
140+
$file = $this->_mediaDirectory->getAbsolutePath($file);
141+
$imageSize = @getimagesize($file);
142+
if ($imageSize) {
143+
return [
144+
'width' => (int)$imageSize[0],
145+
'height' => (int)$imageSize[1]
146+
];
147+
}
148+
}
149+
150+
return [];
151+
}
152+
129153
/**
130154
* @param $width
131155
* @param $height

0 commit comments

Comments
 (0)