javascript - 以正确的方向显示图像 - Blazor 服务器端
问题描述
我的页面正在显示来自 azure 存储的文件,其中一些是横向的,而另一些是纵向的。我的问题是所有文件都显示为横向。起初我只是尝试添加以下css:
.photo{
image-orientation: from-image;
}
但似乎 css 已被弃用/不适用于边缘和 chrome。
接下来我尝试使用 blueimp 的JavaScript-Load-Image。哪个正在显示图像,但方向没有改变 - 它们仍然以横向显示。
JavaScript:
function RotateImage(fileURL) {
var loadingImage = loadImage(
fileURL,
function (img) {
document.body.appendChild(img)
},
{ orientation: true }
)
return loadingImage;
}
HTML:
<div class="photosGridDiv">
@foreach (var file in currentFiles)
{
<div>
@(JSRuntime.InvokeAsync<object>("RotateImage", file.filePath))
<br />
<a href="@file.filePath">@file.fileName</a>
</div>
}
</div>
解决方案
也许在客户端处理旋转,使用 exif-js(https://github.com/exif-js/exif-js)并应用 CSS 转换。
EXIF.getData(imageElement, function() {
var orientation = EXIF.getTag(this, "Orientation");
if(orientation == 6)
$(imageElement).css('transform', 'rotate(90deg)')
});
推荐阅读
- javascript - Gulp:您是否忘记发出异步完成错误信号
- javascript - 如何避免 about:blank#blocked with window.location?
- flutter - 需要一个“ProductList”类型的值,但得到一个“_Future”类型的值
' - mysql - 从下拉列表Nodejs中选择的值查询数据库
- delphi - 没有收到使用 Indy 发送的 JSON,因为它是由 Stripe API 发送的
- flutter - 如何从我的 Flutter PWA 飞镖代码注册后台同步
- python - 零的numpy处理:区分-0和0
- c# - 如何在 ASP.NET MVC 中使用部分视图使用多个列表
- r - Shiny 无法正确加载 RDS 对象----警告:predict_sbo_predictor 中的错误:外部指针无效?
- vega-lite - 分组条形图:“底部”组名位置