Conditions | 3 |
Paths | 3 |
Total Lines | 24 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
22 | public function calculateWidths(int $fileSize, int $width, int $height): Collection |
||
23 | { |
||
24 | $targetWidths = collect(); |
||
25 | |||
26 | $targetWidths->push($width); |
||
27 | |||
28 | $ratio = $height / $width; |
||
29 | $area = $width * $width * $ratio; |
||
30 | |||
31 | $predictedFileSize = $fileSize; |
||
32 | $pixelPrice = $predictedFileSize / $area; |
||
33 | |||
34 | while (true) { |
||
35 | $predictedFileSize *= 0.7; |
||
36 | |||
37 | $newWidth = (int)floor(sqrt(($predictedFileSize / $pixelPrice) / $ratio)); |
||
38 | |||
39 | if ($this->finishedCalculating($predictedFileSize, $newWidth)) { |
||
40 | return $targetWidths; |
||
41 | } |
||
42 | |||
43 | $targetWidths->push($newWidth); |
||
44 | } |
||
45 | } |
||
46 | |||
60 |