使用与iOS6的Safari浏览器的手机浏览器最好的方式,将文件上传功能使用户能够抓拍照片的选项。不幸的是,在拍摄照片时,照片缩略图在浏览器中正确显示,当您上传到服务器时,文件旋转90度。这似乎是由于iphone设置的exif数据。我有代码,通过旋转图像来定位服务时的方向。但是,我怀疑最好是保存旋转的,正确的图像,这样我就不必担心方向了。我的许多其他照片甚至没有exif数据,如果我能避免它,我不想惹它。PHP iphone/iOS6的上传旋转的问题:什么是保存旋转图像
任何人都可以提出代码来保存图像,以便它的方向正确?
这里是旋转图像的代码。下面的代码将显示正确定向的图像,但是,我想要做的就是保存它,以便随时可以提供服务,而不必担心方向。
此外,我想换成下面的代码impagejpeg
调用,这样任何代码工作于GIF和JPG格式为。
感谢您的建议/代码!
PHP
//Here is sample image after uploaded to server and moved to a directory
$target = "pics/779_pic.jpg";
$source = imagecreatefromstring(file_get_contents($target));
$exif = exif_read_data($target);
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$image = imagerotate($source,90,0);
//echo 'It is 8';
break;
case 3:
$image = imagerotate($source,180,0);
//echo 'It is 3';
break;
case 6:
$image = imagerotate($source,-90,0);
//echo 'It is 6';
break;
}
}
// $image now contains a resource with the image oriented correctly
//This is where I want to save resource properly oriented instead of display.
header('Content-type: image/jpg');
imagejpeg($image);
?>
想出它可以与无头和imagejpeg($图像,$目标)来完成;只适用于jpeg,但这在短期内解决了我的问题。 – user1904273