I've posted here before and got pretty helpful reviews. So, howHow does my code look now.? To keep it really helpful, I just copied this from the middle of one of my projects. Review please?
<?php function findSimilarityBetweenImages($imagePathA, $imagePathB, $accuracy){ //if images are png $imageA = imagecreatefrompng($imagePathA); $imageB = imagecreatefrompng($imagePathB); //if images are jpeg //$imageA = imagecreatefromjpeg($imagePathA); //$imageB = imagecreatefromjpeg($imagePathB); //get image resolution $imageX = imagesx($imageA); $imageY = imagesy($imageA); $pointsX = $accuracy*5; $pointsY = $accuracy*5; $sizeX = round($imageX/$pointsX); $sizeY = round($imageY/$pointsY); //Compare the color of each point while looping through. $y = 0; $match = 0; $num = 0; for ($i=0; $i < $pointsY; $i++) { $x = 0; for($n=0; $n < $pointsX; $n++){ $rgba = imagecolorat($imageA, $x, $y); $colorsa = imagecolorsforindex($imageA, $rgba); $rgbb = imagecolorat($imageB, $x, $y); $colorsb = imagecolorsforindex($imageB, $rgbb); if(colorComp($colorsa['red'], $colorsb['red']) && colorComp($colorsa['green'], $colorsb['green']) && colorComp($colorsa['blue'], $colorsb['blue'])){ $match ++; //Match between points. } $x += $sizeX; $num++; } $y += $sizeY; } //A similarity or percentage of match between the two images. $similarity = $match*(100/$num); return $similarity; } function colorComp($color, $c){ //To see if the points match if($color >= $c-2 && $color <= $c+2) { return true; } else { return false; } } ?>