473,395 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Checking image size

Dear All,

I tried posting this before, but it seems to have disappeared.

I need to check image sizes before the user uploads them. This works in
the Mozilla family on second and subsequent iterations:

if(form.photo1.value != ""){
var piccie = new Image();
piccie.src = "file://" + form.photo1.value;
if(piccie.height > 244 || piccie.height < 236 || piccie.width > 324
|| piccie.width < 316){
alert("Your photo 1 is " + piccie.width + " pixels wide and " +
piccie.height + " pixels high.\n The required dimensions are 320w
x 240h. Please scale your picture");
return false;
}
}

This means the user must try twice on the Mozilla family of browsers.
The first time a hight and width of 0 are returned.

On Opera it does not work at all. The "file://" is needed when this
runs on the server.

I don't know about MSIE as I don't have a server setup on the Windows
side of my computer and very rarely go there.

Any ideas on this? I'd be grateful.

Chris

Jul 23 '05 #1
1 5165
Antonie C Malan Snr wrote:
I need to check image sizes before the user uploads them. This works in
the Mozilla family on second and subsequent iterations:

if(form.photo1.value != ""){
var piccie = new Image();
piccie.src = "file://" + form.photo1.value;
At this point in your code, piccie will not have loaded yet. It's height and width attributes could be
anything from 0 to undefined to some random value.
if(piccie.height > 244 || piccie.height < 236 || piccie.width > 324
|| piccie.width < 316){
alert("Your photo 1 is " + piccie.width + " pixels wide and " +
piccie.height + " pixels high.\n The required dimensions are 320w
x 240h. Please scale your picture");
return false;
}
}

This means the user must try twice on the Mozilla family of browsers.
The first time a hight and width of 0 are returned.
Because in Gecko-based browsers, the height and width attributes are the value of the previous image,
in your case, there is no previous image, so height and width are 0.
On Opera it does not work at all. The "file://" is needed when this
runs on the server.
No, it really isn't. If it's coming from a Web server, then you either don't need the protocol at all,
or it should be http:

Oh I see what you are doing, you are trying to determine the size of an image a user has selected?

You simply can not do that in a Web browser in the default security environment. It would require
having access to the local file system, and you do not have access to the local file system.

It happens to work in Mozilla because the entire page is coming from the local file system, so the
script on the page assumes the image is just loading from the same source as the rest of the page.
I don't know about MSIE as I don't have a server setup on the Windows
side of my computer and very rarely go there.
Internet Explorer has nothing to do with having a Web server set up. It is a Web browser.
Any ideas on this? I'd be grateful.


Yes, what you are atttempting to do - determine the dimensions of an image that has not been uploaded
to the server - using client-side JavaScript in the default security environment is impossible.

You will have to allow the user to upload the image, and then determine the dimensions on the server.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
5
by: Tongu? Yumruk | last post by:
I have a little proposal about type checking in python. I'll be glad if you read and comment on it. Sorry for my bad english (I'm not a native English speaker) A Little Stricter Typing in Python...
7
by: Matt | last post by:
I want to test the blank data in required field. If the user enter blank data, the following code still not work. But if I test for the length of a string, it doesn't work also, any ideas??...
8
by: Chris Dewin | last post by:
Hi. I run a website for my band, and the other guys want an image gallery. I'm thinking it would be nice and easy, if we could just upload a jpg into a dir called "gallery/". When the client...
1
by: John Thompson | last post by:
We're sooo close. When we load the page to upload the image, all of the prms go through except the binary image data. Using SQL server with the data type set to "image". Please help! Thanks-...
6
by: nichughes | last post by:
Hello all, A question relating to http://www.entrust-systems.net/ Just for a change I have run into a problem that seems to be OS specific rather than browser specific - the box image that is...
3
by: =?Utf-8?B?SlIx?= | last post by:
I would like to add text to an image. I have tried to use DrawString and it works on some images but on others it is very very small. I am pretty sure it has something to do with the size of the...
2
by: Adam Teale | last post by:
hey guys Is there a builtin/standard install method in python for retrieving or finding out an image's dimensions? A quick google found me this:...
3
by: DavidPr | last post by:
On my image process page I want to first check to see that the picture title ($item_title) isn't in use, if not the script moves to the next conditional. Now we check to make sure that the image...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.