DefaultImageFormatReader.php: update

This commit is contained in:
Zankaria 2025-03-17 22:48:00 +01:00
parent cd8d93ad05
commit 63ae8f338f

View file

@ -2,17 +2,25 @@
namespace Vichan\Service\Media; namespace Vichan\Service\Media;
class DefaultImageFormatReader implements ImageFormatReader { /**
/** * 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. * 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 * 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. * are swapped, i.e. the contain the height and width, respectively.
*/ */
class DefaultImageFormatReader implements ImageFormatReader {
public function getSizes(string $file_path): array { public function getSizes(string $file_path): array {
$ret = \getimagesize($file_path); $ret = \getimagesize($file_path, $info);
if ($ret === false) { if ($ret === false) {
throw new \RuntimeException("Could not read image sizes of '$file_path'"); 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; return $ret;
} }
} }