-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_file_ratio.php
79 lines (47 loc) · 1.48 KB
/
get_file_ratio.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
$file = $_GET['file'];
$dotPos = strpos($file, '.');
if ($dotPos === false)
{
$path = $file . '.jpg';
}
else
{
$fileWithNoSuffix = substr($file, 0, ($dotPos)) ;
$path = $fileWithNoSuffix . '.jpg';
}
$result = new stdClass();
$dir = '/var/www/vhosts/justinwylliephotography.com/jwp2.justinwylliephotography.com/clients/ocva/awards2017/thumbs/';
$filePath = $dir . '/' . $path;
$test = '/var/www/vhosts/justinwylliephotography.com/jwp2.justinwylliephotography.com/clients/ocva/awards2017/thumbs/20170509-_D805207.jpg';
$sizeInfo = getimagesize($filePath);
if ($sizeInfo === false) {
$result->result = false;
}
else
{
$result->result = true;
$largestSide = max($sizeInfo[0], $sizeInfo[1]);
$smallestSize = min($sizeInfo[0], $sizeInfo[1]);
$ratio = number_format(($largestSide / $smallestSize), 2);
$result->path = $path;
switch ($ratio) {
case 1:
$result->size = ['10" x 10"', '12" x 12"'];
break;
case 1.25:
$result->size = '10" x 8"';
break;
case 1.5:
$result->size = ['9" x 6"', '12" x 8"'];
break;
case 1.77:
$result->size = '12" x 8"';
break;
default:
$result->size = ['9" x 6"', '12" x 8"'];
}
}
header('Content-Type: application/json');
echo json_encode($result);
?>