daveyboy thanks for your advice,
if i use .png format for the picture it works only if i run imagecolorallocate first, but if i use .jpeg format it works itself without needing imagecolorallocate, i did not understand why!
Secondly, getimagesize() does not work! here is the code;
<?
header("content-type: image/png");
$img=imagecreate(400,200);
$inf=getimagesize("img.png");
echo $inf[0];
?>
it says,
<b>Warning</b>: getimagesize: Unable to open 'img.png' for reading.