switch (mime_content_type($filepath)) {
case "image/jpeg":
break;
case "image/png":
$marker = file_get_contents($filepath, false, null, 25, 1);
$channels = match(ord($marker)) {
2, 3 => 3,
6 => 4,
default => throw new DriverException(),
};
break;
case "image/webp":
default: throw new DriverException();
}
GdImage::createImageDescriptor( throws an Exception when it can not determine the number of channels used by the image to encode.