使用PHP / GD将二进制数据保存为JPEG而不会丢失元数据


Use PHP / GD to Save Binary Data as a JPEG Without Losing Metadata

我有一个图像作为二进制数据提供给我的PHP脚本。我想将此图像作为 jpeg 保存到服务器上的目录中。我可以使用以下代码完成此操作:

// create image resource from the binary data
$image = imagecreatefromstring($binary_data);
// save the image resource as a jpeg
imagejpeg($image, $directory);

问题是,当我这样做时,我认为它正在创建一个包含新元数据的新图像。有没有办法将二进制数据另存为图像并保留原始二进制数据?

你为什么不直接保存$binary_data而不是通过GD
传递它file_put_contents($directory, $binary_data)

使用 Meta 数据,您可以通过 iptcparse(( 读取数据,并通过 iptcembed(( 将其重新嵌入

此评论几乎可以完全按照您的要求 -> http://us3.php.net/manual/en/function.iptcembed.php#85887

对于EXIF数据,您可以通过exif-read-data((读取它,但是没有办法将该数据写回文件,但希望这应该足以让您开始正确的方向。