473,597 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.val ue;
if(piccie.heigh t > 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 5185
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.val ue;
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.heigh t > 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*****@agrico reunited.com>
comp.lang.javas cript 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
11752
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 table in MySQL with the path & filename to the image. I have successfully uploaded and performed an update query on the database, but the problem I have is I cannot retain the primary key field in a variable which is then used in a SQL update...
5
2990
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 - A Proposal As we all know, one of the best things about python and other scripting languages is dynamic typing (yes I know it has advantages and disadvantages but I will not discuss them now). Dynamic typing allows us to change types of...
7
3068
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?? thanks!! if (InputForm.username.value == '') alert("username is required");
8
4806
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 clicks the "gallery" link, a cgi script could search the gallery/ dir, and create thumbnails of any jpeg images that don't already have a thumbnail associated with them. The script could then generate a page of clickable thumbnails. A few questions:
1
2497
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- John
6
1979
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 acting as a faux border for the main text block shows nasty image effects on the outside when using either Firefox or Konqueror on Suse Linux. This image is set to resize with the browser window (and hence the text) and this seems to be what...
3
2499
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 image but I have had varying results on multiple images. Is there anyway to make the text a fixed size on the image. Similar to putting a date on a photograph.
2
4119
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: http://www.pythonware.com/library/pil/handbook/introduction.htm but it looks like it is something I will need to install - I'd like to be able to pass my script around to people without them needing any
3
1239
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 name ($image) isn't already in the database. (The file name is $image and the table row is image_name.) If the image name isn't in the database the script continues. I have tested for the picture title and the script will fail and return an error...
0
7969
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7886
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8272
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8035
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8258
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6688
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3886
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2404
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1238
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.