下面是一个使用 gd 缩放图像,以及使用 PEL 复制 Exif 和 ICC 颜色配置文件的示例:
function scaleImage($inputPath, $outputPath, $scale) {
$inputImage = imagecreatefromjpeg($inputPath);
list($width, $height) = getimagesize($inputPath);
$outputImage = imagecreatetruecolor($width * $scale, $height * $scale);
imagecopyresampled($outputImage, $inputImage, 0, 0, 0, 0, $width * $scale, $height * $scale, $width, $height);
imagejpeg($outputImage, $outputPath, 100);
}
function copyMeta($inputPath, $outputPath) {
$inputPel = new \lsolesen\pel\PelJpeg($inputPath);
$outputPel = new \lsolesen\pel\PelJpeg($outputPath);
if ($exif = $inputPel->getExif()) {
$outputPel->setExif($exif);
}
if ($icc = $inputPel->getIcc()) {
$outputPel->setIcc($icc);
}
$outputPel->saveFile($outputPath);
}
copy('https://i.stack.imgur.com/p42W6.jpg', 'input.jpg');
scaleImage('input.jpg', 'without_icc.jpg', 0.2);
scaleImage('input.jpg', 'with_icc.jpg', 0.2);
copyMeta('input.jpg', 'with_icc.jpg');
输出图像:

输入图像:
