title: Get remote image with PHP and show it with GD
body: <p>I have a code in my website to show remote <strong>Gravatar</strong> portraits or uploaded images. Uploaded is ok, but i can't get the gravatar images. </p>
  
  <p>Cant use <strong>file_get_contents</strong> because it´s not allowed on my host. </p>
  
  <p>Heres the start check for the file</p>
  
  <pre><code>if(file_exists($arUser['imagem'][0])){
      $imgPath = $arUser['imagem'][0]; //Usar a imagem enviada
  }elseif(!strlen($arUser['imagem'][0]) &amp;&amp; checkRemoteFile('http://www.gravatar.com/avatar/'.md5($arUser['email'][0]).'fs=150')){
      $imgPath = 'http://www.gravatar.com/avatar/'.md5($arUser['email'][0]).'fs=150';
  }else           
      $imgPath = '../img/social_noavatar_150.jpg'; //Temporario
  </code></pre>
  
  <p>So this doesn´t work:</p>
  
  <pre><code>$imgData = getimagesize($imgPath);
  $src = imagecreatefromwhatever($imgPath);   
  </code></pre>
  
  <p>I know I should replace:</p>
  
  <p><em>$imgPath = 'http://www.gravatar.com/avatar/'.md5($arUser['email'][0]).'fs=150';</em></p>
  
  <p>with something like:</p>
  
  <p><em>$imgPath = GetFileData('http://www.gravatar.com/avatar/'.md5($arUser['email'][0]).'fs=150');</em></p>
  
  <p>or</p>
  
  <p>*$imgPath = file_get_contents('http://www.gravatar.com/avatar/'.md5($arUser['email'][0]).'fs=150');*</p>
  
  <p>Got error with both and I can´t create the image:</p>
  
  <p>I´ve searched for the answer but the others didn't fited to me.</p>
  
  <p>Sorry for my bad english. :(</p>
  
  <p>Note:</p>
  
  <pre><code>function imagecreatefromwhatever($image){
  $info = pathinfo($image);
  $extension = strtolower($info['extension']);
  switch($extension) {
      case "jpg":
          return imagecreatefromjpeg($image);
      break;
      case "jpeg":
          return imagecreatefromjpeg($image);
      break;
      case "png":
          return imagecreatefrompng($image);
      break;
      case "gif":
          return imagecreatefromgif($image);
      break;
      default:
          return imagecreatefromjpeg($image);
  }
  }
  </code></pre>