在使用PHP上载之前,根据EXIF方向确定图像方向
我知道这个话题对你们大多数人来说可能很容易,但我在过去的两天里一直在为这个话题争论,没有任何进展 我正在为自己做一个web应用程序,不需要安全性,因为这是非生产性的 以下脚本工作正常,当我使用以下脚本直接从相机上传图片时,问题仍然存在:在使用PHP上载之前,根据EXIF方向确定图像方向,php,exif,capture,Php,Exif,Capture,我知道这个话题对你们大多数人来说可能很容易,但我在过去的两天里一直在为这个话题争论,没有任何进展 我正在为自己做一个web应用程序,不需要安全性,因为这是非生产性的 以下脚本工作正常,当我使用以下脚本直接从相机上传图片时,问题仍然存在: <input id="photoBox" type="file" class="form-control-file" accept="image/*" capture="camera" name="photo"/> 我的意图很清楚。在上传之前,根据
<input
id="photoBox"
type="file"
class="form-control-file"
accept="image/*"
capture="camera"
name="photo"/>
我的意图很清楚。在上传之前,根据EXIF方向旋转img,然后继续将其存储在磁盘上。
如果可能的话,我打算用同样的photoPlant(arg)
功能来完成
谢谢。好的。在几次无法解释的否决票和迪诺科德龙的一句非常有用的评论后,这就是我一直在寻找的答案 我必须为PHP7安装并启用Imagick。 这不是一个简单的工作,但谷歌有一些指南。根据您的版本/操作系统,安装说明会有所不同,因此请小心操作 上传部分更改了我的上传功能(来自原始帖子)。 上面写着:
if (empty($errors)){
// old code here.
}
它已更改为进行以下验证:
if (empty($errors)) {
// this is my new validation code.
$img = new Imagick($fileTmpName);
$orient = $img->getImageOrientation();
if($orient === 6){
// we need to rotate it 90deg
$img->rotateImage("rgba(255, 255, 255, 0.0)", 90);
}
if ($orient === 3){
// we need to rotate it 180deg
$img->rotateImage("rgba(255, 255, 255, 0.0)", 180);
}
// Note that imagick does the storage for me as well!
$img->writeImage("gallery/" . $fileName);
}
else{
$out .= "Errors on upload";
}
这解决了我的所有问题,并有了合理的响应时间。
希望像我这样的新手能从这篇文章中获得一些技能收益
作为告别信,我需要补充。。。如果你对一篇帖子投了否决票,请评论你这样做的原因,因为这个话题在这里已经讨论过无数次了,但是在对这么多老帖子进行了两天的研究之后,我没有找到它不起作用的原因
特别感谢迪诺科龙,他用大约10个字把我送到了正确的方向 这里有一些医生让你开始和@DinoCoderSaurus我不知道为什么这个问题在社区中如此讨厌。看来我的反对票比答案多,但我的单一答案解决了我的问题。我真的不知道去哪里找,所以非常感谢你。请提交作为最终答案,我会很高兴地标记为正确,因为它是!
if (empty($errors)) {
// this is my new validation code.
$img = new Imagick($fileTmpName);
$orient = $img->getImageOrientation();
if($orient === 6){
// we need to rotate it 90deg
$img->rotateImage("rgba(255, 255, 255, 0.0)", 90);
}
if ($orient === 3){
// we need to rotate it 180deg
$img->rotateImage("rgba(255, 255, 255, 0.0)", 180);
}
// Note that imagick does the storage for me as well!
$img->writeImage("gallery/" . $fileName);
}
else{
$out .= "Errors on upload";
}