How can PHP developers handle cases where only the base image is displayed or downloaded instead of the specified parameterized image?

When only the base image is displayed or downloaded instead of the specified parameterized image, PHP developers can check if the parameterized image exists before serving it. If the parameterized image does not exist, they can fallback to serving the base image.

$baseImage = 'base.jpg';
$parameterizedImage = $_GET['image'];

if (file_exists($parameterizedImage)) {
    header('Content-Type: image/jpeg');
    readfile($parameterizedImage);
} else {
    header('Content-Type: image/jpeg');
    readfile($baseImage);
}