What are potential pitfalls when using MD5 hashing for image comparison in PHP?

When using MD5 hashing for image comparison in PHP, a potential pitfall is that MD5 is not collision-resistant, meaning two different images could potentially produce the same hash. To avoid this issue, consider using a more secure hashing algorithm such as SHA-256 for image comparison.

$image1 = 'image1.jpg';
$image2 = 'image2.jpg';

$hash1 = hash_file('sha256', $image1);
$hash2 = hash_file('sha256', $image2);

if ($hash1 === $hash2) {
    echo 'Images are identical.';
} else {
    echo 'Images are different.';
}