| Conditions | 2 |
| Paths | 1 |
| Total Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | public function getVariations(ScaleableImage $scaleableImage): array |
||
| 17 | { |
||
| 18 | $fileSize = $scaleableImage->filesize(); |
||
| 19 | $width = $scaleableImage->width(); |
||
| 20 | |||
| 21 | $ratio = $scaleableImage->height() / $width; |
||
| 22 | $area = $width * $width * $ratio; |
||
| 23 | $pixelPrice = $fileSize / $area; |
||
| 24 | |||
| 25 | $stepAmount = $fileSize * $this->stepModifier; |
||
| 26 | |||
| 27 | $variations = []; |
||
| 28 | |||
| 29 | do { |
||
| 30 | $newWidth = (int) floor(sqrt(($fileSize / $pixelPrice) / $ratio)); |
||
| 31 | |||
| 32 | $variations[$newWidth] = $newWidth * $ratio; |
||
| 33 | |||
| 34 | $fileSize -= $stepAmount; |
||
| 35 | } while ($fileSize > 0); |
||
| 36 | |||
| 37 | return $variations; |
||
| 38 | } |
||
| 39 | } |
||
| 40 |