title: Get remote image using cURL then resample
body: <p>I want to be able to retrieve a remote image from a webserver, resample it, and then serve it up to the browser AND save it to a file. Here is what I have so far:</p>
  
  <pre><code>$ch = curl_init();
  
  // set URL and other appropriate options
  curl_setopt($ch, CURLOPT_URL, "$rURL");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  curl_setopt($ch, CURLOPT_HEADER, 0);
  
  // grab URL and pass it to the browser
  $out = curl_exec($ch);
  
  // close cURL resource, and free up system resources
  curl_close($ch);
  
  $imgRes = imagecreatefromstring($out);
  imagejpeg($imgRes, $filename, 70);
  
  header("Content-Type: image/jpg");
  imagejpeg($imgRes, NULL, 70);
  exit();
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>Updated to reflect correct answer based on discussion below</p>