【问题标题】:uploaded image orientation issues上传的图像方向问题
【发布时间】:2020-05-13 21:31:06
【问题描述】:

我整天都在寻找解决方案,但似乎无法找到合适的解决方案。

问题(我认为)很简单。当图像上传到我的页面时,它会显示在 img 元素中。现在由于某种原因,它自己从纵向旋转到横向。 我切断了中间人并将 img 标签连接到路径。 问题仍然存在。

如果我在 ps 中打开它并将其另存为新的 jpeg,它是固定的,但这不是一个可行的选择,因为图像将直接从客户端上传。

在其他程序(ps、paint、photos、photos3d)中不存在这个问题

在我的挖掘中,我发现这可能是由图像的 exif 数据引起的。 其他所有内容都会忽略该数据,或者正确读取它。

谁能告诉我如何解决这个问题?

我尝试添加 image-orientation:0deg 和 image-orientation:from-image 到没有结果。

另外,为了我的理智,有谁知道为什么这会是一个问题?

编辑这不会发生在 Firefox 上。话虽如此,我不能强迫每个人都避免使用 chrome

提前致谢

【问题讨论】:

    标签: image orientation exif


    【解决方案1】:

    好的,所以我到处寻找并找到了一些方法来旋转图像客户端并添加 css 使其看起来合法。然后我意识到这一切都被浪费了,因为它会导致图像在正确显示它的浏览器中过度旋转。

    最终将其带到服务器端并在那里修复(基于 exif 旋转并删除 exif 数据)

    我将包含控制器代码

    public JsonResult NormalizeOrientation(HttpPostedFileBase file)
        {
            Image img = Image.FromStream(file.InputStream);
            if (Array.IndexOf(img.PropertyIdList, 274) > -1)
            {
                var orientation = (int)img.GetPropertyItem(274).Value[0];
                switch (orientation)
                {
                    case 1:
                        // No rotation required.
                        break;
                    case 2:
                        img.RotateFlip(RotateFlipType.RotateNoneFlipX);
                        break;
                    case 3:
                        img.RotateFlip(RotateFlipType.Rotate180FlipNone);
                        break;
                    case 4:
                        img.RotateFlip(RotateFlipType.Rotate180FlipX);
                        break;
                    case 5:
                        img.RotateFlip(RotateFlipType.Rotate90FlipX);
                        break;
                    case 6:
                        img.RotateFlip(RotateFlipType.Rotate90FlipNone);
                        break;
                    case 7:
                        img.RotateFlip(RotateFlipType.Rotate270FlipX);
                        break;
                    case 8:
                        img.RotateFlip(RotateFlipType.Rotate270FlipNone);
                        break;
                }
                // This EXIF data is now invalid and should be removed.
                img.RemovePropertyItem(274);
    
            }
            MemoryStream ms = new MemoryStream();
            img.Save(ms, ImageFormat.Jpeg);
            return Json(new { base64imgage = Convert.ToBase64String(ms.ToArray()) }
          , JsonRequestBehavior.AllowGet);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-20
      • 2012-04-15
      相关资源
      最近更新 更多