<?php
function LoadPNG($imgname)
{
    /* Attempt to open */
    $im = @imagecreatefrompng($imgname);
 
    /* See if it failed */
    if(!$im)
    {
        /* Create a blank image */
        $im  = imagecreatetruecolor(150, 30);
        $bgc = imagecolorallocate($im, 255, 255, 255);
        $tc  = imagecolorallocate($im, 0, 0, 0);
 
        imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
 
        /* Output an error message */
        imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
    }
 
    return $im;
}
 
function imagehex($image)
        {
            $size = getimagesize($image['path']);
            $func = 'imagecreatefrom'.$image['type'];
            $imageres = $func($image['path']);
            $zone = imagecreate(20, 20);
            imagecopyresized($zone, $imageres, 0, 0, 0, 0, 20, 20, $size[0], $size[1]);
            $colormap = array();
            $average = 0;
            $result = array();
            for($x=0; $x<20; $x++)
            {
                for($y=0; $y<20; $y++)
                {
                    $color = imagecolorat($zone, $x, $y);
         
                    $color = imagecolorsforindex($zone, $color);
     
                    $colormap[$x][$y]= 0.212671 * $color['red'] + 0.715160 * $color['green'] + 0.072169 * $color['blue'];
                    $average += $colormap[$x][$y];
                }
            }
            $average /= 400;
            for($x=0; $x<20; $x++)
            {
                for($y=0; $y<20; $y++)
                {
                    $result[]=($x<10?$x:chr($x+97)) . ($y<10?$y:chr($y+97)) . round(2*$colormap[$x][$y]/$average);
                }
            }
            return $result;
        }
 
header('Content-Type: image/png');
 
$img1 = LoadPNG('C:\picture1.png');
$img2 = LoadPNG('C:\picture2.png');
 
$hex1 = imagehex($img1);
$hex2 = imagehex($img2);
 
$result=(count($hex1) + count($hex2)) - count(array_diff($hex2,$hex1))-400;
        return $result / ( ( count($hex1) + count($hex2) ) / 2 );
 
echo $result
 
?>