获得图像宽度高度 [英] get image width & height

查看:89
本文介绍了获得图像宽度高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立网站,我想使用jquery获取图像大小,即宽度或高度. 这是我的代码,

I am building website,i want to get image size i.e.width or height using jquery. here is my code,

var photograf=('url(upload/'+ nm +'.jpg)');
var imgwidth=photograf.width();
var imgheight=photograf.height(); 

但是它不起作用.我知道这是错误的,但是我已经做过上面的事情. 请以其他或正确的方式帮助我. 谢谢.

but it's not working.i know it's wrong but i have do above thing. please help me other or correct way. thank you.

推荐答案

您正在将photograf初始化为字符串,其中没有width()height()函数.您实际上没有尝试使用jQuery或其他方式加载图像.实际上,代码中的任何地方都没有jQuery.

You're initializing photograf as a string, which has no width() or height() functions. Nowhere are you actually attempting to load an image, with jQuery or otherwise. In fact, there is no jQuery anywhere in your code.

您可以将图像添加到页面中,然后找到所得元素的宽度/高度,或创建一个新的Image对象:

You could either add the image to the page, and then find the resulting element's width/height, or create a new Image object:

photograf = new Image();
photograf.src = 'upload/' + nm + '.jpg');
var width = photograf.width;
var height = photograf.height;

这篇关于获得图像宽度高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆