/    Sign up×
Community /Pin to ProfileBookmark

retrieving image dimensions in Firefox

hi all,
i tried below code for retrieving image dimensions. It works in IE, however it doesnt work in firefox. Can any one help me to make this code work in Firefox too?

<html>

<head>

<script language=’JavaScript’>

function getImgSize(imgsrc)

{

var newImg = new Image();

newImg.src = imgsrc;

var height = newImg.height;

var width = newImg.width;

var filename = imgsrc.replace(/^.*/, ”)

alert(“‘” + filename + “‘ is ” + width + ” by ” + height + ” pixels in size.”);

alert (‘The image size is ‘+width+’*’+height);

}

</script>

</head>

<body>

<form>

<INPUT TYPE=”file” NAME=”fileName” >

<p>

<INPUT TYPE=”button” VALUE=”check image dimensions” OnCLICK=”getImgSize(this.form.fileName.value)”>

</form>

</body>

</html>

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@FangSep 15.2010 — Doesn't work in any browser.

Upload the image to the server and retrieve the dimensions with Ajax
Copy linkTweet thisAlerts:
@gauri_kakadeauthorSep 15.2010 — thanks for the response

can u please elaborate some more on it?
Copy linkTweet thisAlerts:
@FangSep 15.2010 — Ask in the server side language forum you are using.
Copy linkTweet thisAlerts:
@gauri_kakadeauthorSep 15.2010 — ok so i tried below code in php. still i face issues in firefox..

<html>

<body>

<form method="POST" action="">

<INPUT TYPE="file" NAME="fileName" >

<p>

<INPUT TYPE="submit" VALUE="check image dimensions" name="btn_chk_dimen">

<?php $image=$_REQUEST['fileName']; ?>

</form>

</body>

</html>

<?php

$img_dimen=getimagesize($image);

echo "Width=".$img_dimen[0]."Height=".$img_dimen[1];

?>
Copy linkTweet thisAlerts:
@Jarrod1937Sep 15.2010 — You sure the path to the image file is correct (hint, its not if the file is not in the same directory as the script)? You'll want to prepend either a correct relative or absolute path to the image files before you use the function getimagesize. First, just simplify your script and make sure you get one portion working before moving onto integrating it with a form request.

Place a test image in your images directory and simply use this code to get the image dimension portion working:
[code=php]
$path='path_to_image_directory'; // either relative or absolute
$image='test_file_name.jpg';
$img_dimen=getimagesize($path.$image);
echo "Width=".$img_dimen[0]."Height=".$img_dimen[1];
[/code]
×

Success!

Help @gauri_kakade 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.24,
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,
)...