/    Sign up×
Community /Pin to ProfileBookmark

Ok, I am still having problems with images!

I have an image in a file that I need to determine the pixel dimensions.

I can’t seem to load the file in and determine the dimensions of the thing. Everything I try ( and I have tried lots of things ) the dimensions come out as 0,0, meaning my code is rubbish, I suppose.

Any ideas?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Mr_JJun 08.2008 — Do you mean like this?

myImage = new Image()

myImage.src = "imagename.jpg"

myImageWidth=myImage.width

myImageHeight=myImage.height
Copy linkTweet thisAlerts:
@Logic_AliJun 08.2008 — Do you mean like this?

myImage = new Image()

myImage.src = "imagename.jpg"

myImageWidth=myImage.width

myImageHeight=myImage.height[/quote]
Are you sure you meant to say that?
Copy linkTweet thisAlerts:
@Logic_AliJun 08.2008 — Ok, I am still having problems with images!

I have an image in a file that I need to determine the pixel dimensions.

I can't seem to load the file in and determine the dimensions of the thing. Everything I try ( and I have tried lots of things ) the dimensions come out as 0,0, meaning my code is rubbish, I suppose.

Any ideas?[/quote]
The dimensions are not available until the image loads, therefore you must be sure that has occurred.

You need to use an [I]onload[/I] handler either to call the function that uses the dimensions, or to set a flag that indicates their availability.

Another way is simply to test that the dimensions are non-zero before doing anything that depends upon them.
×

Success!

Help @SuzanneB spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...