| Conditions | 3 |
| Paths | 1 |
| Total Lines | 21 |
| Code Lines | 14 |
| 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 | $sizes[(int) $newWidth] = (int) $newWidth * $ratio; |
||
| 32 | |||
| 33 | $fileSize = $fileSize * $this->stepModifier; |
||
| 34 | } while ($fileSize > $this->minFileSize && $newWidth > $this->minWidth); |
||
| 35 | |||
| 36 | return $sizes; |
||
| 37 | } |
||
| 38 | } |
||
| 39 |