我正在尝试上传图像并修复图像的旋转,然后将其更新到服务器,我必须使用此链接中的答案:here https://stackoverflow.com/questions/34287437/how-to-check-fix-image-rotation-before-upload-image-using-php#answer-34287543但它仍然无法工作方向错误的图像
php中的代码:
//START Update the user image
if(isset($_POST['user_image_id'])){
$upload_image_id = $_POST['user_image_id'];
$user_image = $_FILES['user_image']['name'];
$filePath = $_FILES['user_image']['tmp_name'];
$image = imagecreatefromstring(file_get_contents($_FILES['user_image']['tmp_name']));
$exif = exif_read_data($filePath);
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$image = imagerotate($image,90,0);
break;
case 3:
$image = imagerotate($image,180,0);
break;
case 6:
$image = imagerotate($image,-90,0);
break;
}
}
// $image now contains a resource with the image oriented correctly
//create image target to upload
$image_target = $folder_target.basename($_FILES['user_image']['name']);
//upload the image the and update the name of the image
if(move_uploaded_file($_FILES['user_image']['tmp_name'], $image_target)){
if ($conn->query("UPDATE `users` SET `image`='$user_image' WHERE `id` LIKE '$upload_image_id'")){
echo 1;
}else{
echo "not update the name, Proplem";
}
}else{
echo 'image not uploaded';
}
}
我使用了图像库“https://github.com/Al-Alloush/JavaScript-Load-Image https://github.com/Al-Alloush/JavaScript-Load-Image”,修复浏览器中图像的方向,但当我提交并将图像上传到服务器时,方向仍然相同
请帮忙, :)
旋转图像后您尚未保存图像。上传前保存如下。
imagejpeg($image, $filePath);
//upload the image the and update the name of the image
if(move_uploaded_file($filePath, $image_target)){
....
}
Note: imagejpeg
应该用于具有JPG
扩大。为了PNG
, use imagepng
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)