我正在使用这个jQuery函数来显示上传前的图片。从移动设备上传的图片,存在exif方向问题。该函数只是用实际文件图像的base64代码更改预览图像的src。
在服务器端(php)上,我使用一个函数在上传时纠正exif旋转。
我能否在jQuery中做类似于我的PHP代码的事情?这样我就可以在上传前显示正确旋转的图片了。 Javascript
在服务器端(php)上,我使用一个函数在上传时纠正exif旋转。
我能否在jQuery中做类似于我的PHP代码的事情?这样我就可以在上传前显示正确旋转的图片了。 Javascript
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function(){
readURL(this);
});
PHP
function image_fix_orientation($filename) {
$exif = exif_read_data($filename);
if (!empty($exif['Orientation'])) {
$image = imagecreatefromjpeg($filename);
switch ($exif['Orientation']) {
case 3:
$image = imagerotate($image, 180, 0);
break;
case 6:
$image = imagerotate($image, -90, 0);
break;
case 8:
$image = imagerotate($image, 90, 0);
break;
}
imagejpeg($image, $filename, 100);
}
}