title: Use PHP / GD to Save Binary Data as a JPEG Without Losing Metadata
body: <p>I have an image that is being fed to my PHP script as binary data. I want to save this image as a jpeg to a directory on my server. I can accomplish this with the following code:</p>
  
  <pre><code>// create image resource from the binary data
  $image = imagecreatefromstring($binary_data);
  
  // save the image resource as a jpeg
  imagejpeg($image, $directory);
  </code></pre>
  
  <p>The problem is that when I do this, I think it is creating a new image that contains new metadata. Is there a way I can save the binary data as an image and preserve the original binary data?</p>