leftypol/inc/Service/Media/DefaultImageFormatReader.php

26 lines
948 B
PHP

<?php
namespace Vichan\Service\Media;
/**
* Do not use this if you can.
*
* Some formats may contain no image or may contain multiple images. In these cases, getimagesize() might not be
* able to properly determine the image size. getimagesize() will return zero for width and height in these cases.
*
* getimagesize() is agnostic of any image metadata.
* If e.g. the Exif Orientation flag is set to a value which rotates the image by 90 or 270 degress, index 0 and 1
* are swapped, i.e. the contain the height and width, respectively.
*/
class DefaultImageFormatReader implements ImageFormatReader {
public function getSizes(string $file_path): array {
$ret = \getimagesize($file_path, $info);
if ($ret === false) {
throw new \RuntimeException("Could not read image sizes of '$file_path'");
}
if ($ret[2] == \IMAGETYPE_UNKNOWN) {
throw new \RuntimeException("Error '$file_path' is not an image");
}
return $ret;
}
}