I got this fixed myself.The reason is because PHP is adding a UTF-8 byte order mark (BOM) at the beginning. So this problem gets fixed when the output buffer is cleaned using ob_clean(); The following worked perfectly.
header('Pragma: public');
header('Cache-control: max-age=0');
header('Content-Type: image');
header("Content-Encoding: gzip");
header("Vary: Accept-Encoding");
ob_clean();
echo gzencode( base64_decode ($result[0]['Icon']) ); // result is the result of query from DB