0

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:

// create image resource from the binary data
$image = imagecreatefromstring($binary_data);

// save the image resource as a jpeg
imagejpeg($image, $directory);

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?

Chris
  • 5,485
  • 15
  • 68
  • 130

2 Answers2

0

Why don't you just save $binary_data instead of passing it through GD
file_put_contents($directory, $binary_data)

Musa
  • 96,336
  • 17
  • 118
  • 137
0

With Meta data, you can read the data via iptcparse() and embed it back in via iptcembed()

This comment will pretty much do exactly what you want -> http://us3.php.net/manual/en/function.iptcembed.php#85887

For EXIF data, you can read it via exif-read-data() but there isn't a way of writing that data back to the file, but hopefully that should be enough to get you started in the right direction.

Jamie Bicknell
  • 2,306
  • 17
  • 35