-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathImageTool.php
52 lines (45 loc) · 1.06 KB
/
ImageTool.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace Ling\Bat;
use Ling\Bat\Util\FastImageSize\FastImageSize;
/**
* The ImageTool class.
*/
class ImageTool
{
/**
* Returns the dimensions as an array of the given image file, based on the file extension.
* The returned array contains two elements:
*
* - 0: int, the width in pixels
* - 1: int, the height in pixels
*
*
*
* The file can be an url too.
*
* This method assumes that the given image file is actually a real image.
* If not, unpredictable results might be returned.
*
*
*
*
* @param string $imageFile
* @return array
*/
public static function getDimensions(string $imageFile): array
{
$util = new FastImageSize();
$size = $util->getImageSize($imageFile);
if (false !== $size) {
return [
$size['width'],
$size['height'],
];
}
list($width, $height) = getimagesize($imageFile);
return [
$width,
$height,
];
}
}