public function equal($image1, $image2)
{
if (is_string($image1)) {
// If string passed, turn it into a Image object
$image1 = Image::createFromFile($image1);
$this->flatten($image1);
}
if (is_string($image2)) {
// If string passed, turn it into a Image object
$image2 = Image::createFromFile($image2);
$this->flatten($image2);
}
// Check if image dimensions are equal
if ($image1->getWidth() !== $image2->getWidth() or $image1->getHeight() !== $image2->getHeight()) {
return false;
} else {
// Loop using image1
for ($y = 0; $y < $image1->getHeight(); $y++) {
for ($x = 0; $x < $image1->getWidth(); $x++) {
// Get image1 pixel
$rgb1 = imagecolorat($image1->getCore(), $x, $y);
$r1 = $rgb1 >> 16 & 0xff;
$g1 = $rgb1 >> 8 & 0xff;
$b1 = $rgb1 & 0xff;
// Get image2 pixel
$rgb2 = imagecolorat($image2->getCore(), $x, $y);
$r2 = $rgb2 >> 16 & 0xff;
$g2 = $rgb2 >> 8 & 0xff;
$b2 = $rgb2 & 0xff;
// Compare pixel value
if ($r1 !== $r2 or $g1 !== $g2 or $b1 !== $b2) {
return false;
}
}
}
}
return true;
}