What are some common pitfalls to avoid when trying to determine image size with PHP?

One common pitfall when trying to determine image size with PHP is not accounting for image types that may not be supported by the function being used. To avoid this, it is important to check the image type before attempting to get the image size. Another pitfall is not handling errors properly, which can lead to unexpected behavior or crashes in the code. It is important to use error handling mechanisms to catch and handle any errors that may occur during the process of determining image size.

// Check image type before attempting to get image size
$image_path = 'image.jpg';
$image_info = getimagesize($image_path);

if($image_info){
    $image_width = $image_info[0];
    $image_height = $image_info[1];
    echo "Image width: $image_width, Image height: $image_height";
} else {
    echo "Error: Unable to get image size";
}