$median) { $hash |= 0x01; } } return sprintf("%016x", $hash); } public static function hash_file($image_path, &$err = null) { if (!$image_path) { return false; } $size = getimagesize($image_path); if (!$size) { $err = "Couldn't get file information"; return false; } $type = $size[2]; if ($type === IMAGETYPE_PNG) { $img = imagecreatefrompng($image_path); } else if ($type === IMAGETYPE_JPEG) { $img = imagecreatefromjpeg($image_path); } else if ($type === IMAGETYPE_GIF) { $img = imagecreatefromgif($image_path); } else { $err = "Invalid image"; return false; } $width = $size[0]; $height = $size[1]; $hash = self::hash($img, $width, $height); if ($hash === false) { $err = "Couldn't process the image"; return false; } return $hash; } }