ILIAS  trunk Revision v11.0_alpha-1843-g9e1fad99175
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ImageSizeCalculator.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 {
28  private function calculateWidthHeight(float $original_width, float $original_height, int $max_size): array
29  {
30  if ($original_width === $original_height) {
31  return [$max_size, $max_size];
32  }
33 
34  if ($original_width > $original_height) {
35  $columns = $max_size;
36  $rows = (float) ($max_size * $original_height / $original_width);
37  return [$columns, $rows];
38  }
39 
40  $columns = (float) ($max_size * $original_width / $original_height);
41  $rows = $max_size;
42  return [$columns, $rows];
43  }
44 
45  private function calculateWidthHeightFromImage(\Imagick $original, int $max_size): array
46  {
47  return $this->calculateWidthHeight(
48  $original->getImageWidth(),
49  $original->getImageHeight(),
50  $max_size
51  );
52  }
53 }