PHP使用ImageCopyResample保留exif数据

PHP使用ImageCopyResample保留exif数据,php,exif,Php,Exif,我想知道是否有一种方法可以在imagecopyresampled函数创建的图像中保留原始图像的exif数据。我的代码: $randomName = Functions::generate_random_string(10); $img = imagecreatefromjpeg($_FILES["file"]["tmp_name"]); $imageSize = getimagesize($_FILES["file"]["tmp_name"]); $ratio = 1 / ($imageSize

我想知道是否有一种方法可以在imagecopyresampled函数创建的图像中保留原始图像的exif数据。我的代码:

$randomName = Functions::generate_random_string(10);
$img = imagecreatefromjpeg($_FILES["file"]["tmp_name"]);
$imageSize = getimagesize($_FILES["file"]["tmp_name"]);
$ratio = 1 / ($imageSize[0] / $imageSize[1]);
$newWidth = 2560;
$newHeight = round($newWidth * $ratio);
$tmp_img = imagecreatetruecolor( $newWidth, $newHeight );
imagecopyresampled( $tmp_img, $img, 0, 0, 0, 0, $newWidth, $newHeight, $imageSize[0], $imageSize[1] );

工作正常,但在创建的图像中没有exif数据。

您可以捕获exif数据并将其作为文件的元数据保存到数据库中

否。EXIF数据是嵌入在JPEG注释字段中的结构化数据。您的新图像是一个全新的、独立的GD图像,将与从原始照片创建的GD图像不共享任何内容。您必须从原始文件中提取JPG注释字段并将其应用于新文件,但这超出了GD的权限