使用與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