Conditions | 7 |
Paths | 2 |
Total Lines | 23 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
17 | public function scale(SplFileInfo $sourceFile, Image $imageObject) : array { |
||
18 | $fileSize = $sourceFile->getSize(); |
||
19 | $width = $imageObject->getWidth(); |
||
20 | $height = $imageObject->getHeight(); |
||
21 | $ratio = $height / $width; |
||
22 | $area = $width * $width * $ratio; |
||
23 | $pixelPrice = $fileSize / $area; |
||
24 | |||
25 | $sizes = []; |
||
26 | |||
27 | do { |
||
28 | // Magic formula. |
||
29 | $newWidth = floor(sqrt(($fileSize / $pixelPrice) / $ratio)); |
||
30 | |||
31 | if ((!$this->maxFileSize || $fileSize <= $this->maxFileSize) && (!$this->maxWidth || $newWidth <= $this->maxWidth)) { |
||
32 | $sizes[(int) $newWidth] = (int) $newWidth * $ratio; |
||
33 | } |
||
34 | |||
35 | $fileSize = $fileSize * $this->stepModifier; |
||
36 | } while ($fileSize > $this->minFileSize && $newWidth > $this->minWidth); |
||
37 | |||
38 | return $sizes; |
||
39 | } |
||
40 | } |
||
41 |