我最近在做一个上传图片的程序,但是由于一些手机拍的照片是打竖拍的,上传后PHP重新创建一个新的缩略图,它帮我把图片打横了,在网上查到要用exif去读Orientation的信息,然后根据情况旋转回来才行,但是这个exif_read_data()不知道是哪里不对,弄了我一个晚上都试不出来。
下面代码最后输出图片是正常能显示的,证明$_FILES['img']['tmp_name']这个的取值是没问题的,求大神
<?php
//获取上传的图片
$source = imagecreatefromjpeg($_FILES['img']['tmp_name']);//读取图片的exif信息
$exif = exif_read_data($_FILES['img']['tmp_name']);//就是这里出问题!!!
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$source = imagerotate($source,90,0);
break;
case 3:
$source = imagerotate($source,180,0);
break;
case 6:
$source = imagerotate($source,-90,0);
break;
}
}
//将图片旋转
$source = imagerotate($source,90,0);
header('Content-type:image/jpg');
//输出图片
imagepng($source);
imagedestroy($source);?>
上图
下面代码最后输出图片是正常能显示的,证明$_FILES['img']['tmp_name']这个的取值是没问题的,求大神
<?php
//获取上传的图片
$source = imagecreatefromjpeg($_FILES['img']['tmp_name']);//读取图片的exif信息
$exif = exif_read_data($_FILES['img']['tmp_name']);//就是这里出问题!!!
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$source = imagerotate($source,90,0);
break;
case 3:
$source = imagerotate($source,180,0);
break;
case 6:
$source = imagerotate($source,-90,0);
break;
}
}
//将图片旋转
$source = imagerotate($source,90,0);
header('Content-type:image/jpg');
//输出图片
imagepng($source);
imagedestroy($source);?>
上图
解决方案 »
- PHP网站上线之数据库问题?求帮助
- paypal跳转 paypal代理支付系统
- utf-8文件加BOMl与不加BOM的影响?有没研究过的?
- Notice: Undefined index问题的解决
- 能不能让联动菜单实现选一级菜单,不是往二级菜单里加内容,而是让其选中二级菜单里的某个选项?
- PHP MySQL 开发网络银行应用 报酬四百美元
- 如何同时更新两个服务器上的mysql数据库呢?
- 我调一个程序,但是其中的代码有些怪?
- 一个很简单的问题,怎样把一个php字符串变量转为实型变量
- 学习PHP,遇到一个很困惑的问题。
- 有没有人使用Dropzone这个插件上传图片被打横了?
- 请教怎么把这里的文字改成点击图片跳转到某链接
//这样试试看