获取远程图像尺寸 [英] Get remote image dimensions
本文介绍了获取远程图像尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出一个URL到图像(而不是图像本身),什么是最有效的得到它的尺寸呢?我想改变高度和宽度属性的图像标记(< IMG>
)如果是大于200×200。但是,如果是小于的话,我想保持一定的尺寸,因为它是。 (我使用ASP.NET/C#)
Given a URL to an image (and not the image itself), what's the most efficient of getting it's dimensions? I would like to change the height and width attributes in the image tag (<img>
) if it is greater than 200x200. However, if it's smaller than that, then I'd like to keep the size as it is. (I'm using ASP.NET/C#)
推荐答案
如果你不想通过加载它首先,你可以用JavaScript这样做是为了检查图像的属性:
If you don't want to check the properties of the image by loading it first you can do it with javascript:
<img src="image.jpg" onload="if( this.width > 200 ) this.width = 200;">
这篇关于获取远程图像尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文