使用jquery的远程图像属性 [英] remote image properties using jquery
问题描述
目前我正在尝试获取远程图像宽度/高度。我正在开发一个链接共享模块,就像你在Facebook上粘贴一个链接,你可以看到标题,描述和图像。
Currently i am trying to get remote image width/height. I am developing a link sharing module something like when you paste a link on facebook, you can see title, description and images.
所以我尝试使用php getimagesize来获取图像宽度/高度非常慢。
So i tried using php getimagesize to get image width/height its very slow.
所以我正在考虑使用jquery解决方案来获取远程图像宽度/高度,以便我可以过滤图像宽度小于100px。
So i am thinking of using jquery solution to get remote image width/height so that i can filter image width less then 100px.
我是jquery / javascript的新手
I am new in jquery/javascript
我试过类似
var img = $('#imageID');
var width = img.clientWidth;
var height = img.clientHeight;
$('#info').html(width+'.. height: '+height);
它不工作并返回undefined .. height:undefined
Its not working and return undefined .. height: undefined
感谢任何帮助。
谢谢
推荐答案
试试这个:
var img = new Image();
img.src = 'http://your.url.here/image.png';
img.onload = function() {
$('#info').text('height: ' + img.height + ' width: ' + img.width);
};
此方法可让您获取图片信息,而无需< ; img>
标签。现在,也许你想要图像在页面上,所以你做@patrick建议的那种情况。
This approach would let you get the image info without having to have an <img>
tag at all. Now, perhaps you want the image to be on the page, so you'd do what @patrick suggests in that case.
这篇关于使用jquery的远程图像属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!