There are many ways to do it, for the parsing part try google (search for regex)
To write the file, this is easiest way imo :
$pictureURL = "http://www.gofuckyourself.com/skins/realitycash/images/newthread.gif";
$file = implode("", file($pictureURL));
$handle = fopen("newthread.gif", "w+b");
fwrite($handle, $file);
fclose($handle);