mi funziona pure questo:
codice:
function compress($srcName, $dstName){
	$fp = fopen($srcName, "r");
	$data = fread ($fp, filesize($srcName));
	fclose($fp);
	$zp = gzopen($dstName, "w");
	gzwrite($zp, gzcompress($data));
	gzclose($zp);
}
compress("test.jpg", "test.gz");


function uncompress($srcName){
	$zp = gzopen($srcName, "r");
	$data=gzread($zp,filesize($srcName));
	gzclose($zp);
	$data=gzuncompress($data);
	header("Content-type: image/jpeg");
	echo $data;
}
uncompress("test.gz");