dpfqy5976 2018-09-26 18:42 采纳率: 100%
浏览 104

Swift以纵向模式捕获照片并上传到服务器 - 上传的图像显示方向错误

If I take a picture with my iPhone in portrait mode, and send this picture with alamofire to server -> the image will stored perfectly. If I try to use this picture in html, the orientation is wrong. The image is rotated -90 degrees. I tried to save the image in jpg, and png format, but I have the same issue both.

Alamofire.upload(
        multipartFormData: { multipartFormData in
            multipartFormData.append(imageData, withName: "image", fileName: "image.png", mimeType: "image/png")
    },
        to: SERVER_URL,
        encodingCompletion: { encodingResult in
            switch encodingResult {.....

On the server side:

<?php
.....
$response['error'] = "NULL";
$filename = uniqid() . ".png";
move_uploaded_file($_FILES['image']['tmp_name'], "image/" . $filename) ...... 
 ?>

I think there will be 2 different solution, but I could not find the correct way. 1) I have to change the orientation on my iPhone device somehow 2) I have to change the orientation on the server side before I upload to the server.

(I don't want to make the solution on the client side)

  • 写回答

1条回答 默认 最新

  • doob0526 2018-09-26 19:00
    关注

    You can get UIImage orientation using imageOrientation property and pass it to the server side as a parameter, and then to decide what to do on the backend.

    Also you can change image orientation using the code below:

    let pngImage = #imageLiteral(resourceName: "yourImageFileName")
    let image = UIImage(cgImage: pngImage.cgImage, scale: pngImage.scale,   orientation: UIImage.Orientation.up)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺