Javascript reading image fileSize in Firefox

  • joebert
  • joeberterator
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13406
  • Loc: FL
  • Status: Offline

Post October 17th, 2004, 6:21 am

In IE, and from what I've read Opera, & Netscape, after an image(or anything else for that matter) loads on the page most of the it's attributes are accessable. (dateLastModified, fileSize, ect..)

Apparently that's not so in Firefox, anyone know how I can read an images fileSize in Firefox ? I can't do anything on the server side because theese images will never see the server from this page, it's all DHTML.

Example of what I'm doing,
Code: [ Select ]
function preview(source){
  image = new Image();
  image.src = "file:///" + source;
  if(navigator.appName.indexOf("Microsoft") == -1){
   image.onload = readDetails;
  }else{
   window.setTimeout("readDetails()", 1000);
  }
}
function readDetails(){
  var details = {fSize:image.fileSize, h:image.height, w:image.width};
.....proceed with creating preview, ect......
}
..........HTML.......
<input type="file" onchange="preview(this.value)">
  1. function preview(source){
  2.   image = new Image();
  3.   image.src = "file:///" + source;
  4.   if(navigator.appName.indexOf("Microsoft") == -1){
  5.    image.onload = readDetails;
  6.   }else{
  7.    window.setTimeout("readDetails()", 1000);
  8.   }
  9. }
  10. function readDetails(){
  11.   var details = {fSize:image.fileSize, h:image.height, w:image.width};
  12. .....proceed with creating preview, ect......
  13. }
  14. ..........HTML.......
  15. <input type="file" onchange="preview(this.value)">

Basically a preview utility for isometric buildings i'm redoing & it would be nice to have the filesize restriction detection working in Firefox. :?
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post October 17th, 2004, 6:21 am

  • Denni08
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Oct 19, 2004
  • Posts: 112
  • Loc: Cincy Ohio
  • Status: Offline

Post October 20th, 2004, 8:45 am

I would suggest you to get a new server.
  • joebert
  • joeberterator
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13406
  • Loc: FL
  • Status: Offline

Post October 20th, 2004, 9:14 am

This isn't an upload project Denni :wink: that's allready taken care of.

This has no interaction with the server other than the server sending the page to the user.
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jul 06, 2004
  • Posts: 1891
  • Loc: Las Vegas
  • Status: Offline

Post October 20th, 2004, 7:27 pm

Joebert, can you use php on this project?
There is a php function called getimagesize() which returns an array containing width, height, image type and a html compatible width height string. For jpgs, it also returns number of channels and bits per pixel.
It supports the following formats:
GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP, IFF, JP2, JPX, JB2, JPC, XBM, or WBMP

and DOESN'T require the gd lib.

You could use php to generate your javascript function calls. I do it all the time.

More info here: http://www.php.net/getimagesize
  • joebert
  • joeberterator
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13406
  • Loc: FL
  • Status: Offline

Post October 21st, 2004, 5:28 am

That's the thing spock, this isn't meant to touch the server. It's actually meant to save trips to the server :lol:

Take a look at one of the city blocks at Pixel Acres, people are making images that span across multiple plots. Rather than upload/test/upload/test/ect.. to get the positioning right they can use the utility to test positioning by innerHTML'ing an img tag with the source set to "file:///" + browseButton.value; so nothing has to see the server untill it's ready.

The way I did it before required people to click the view they need, this time it reads the width/height & figures it out on its own & warning them if it's an invalid dimension.(which is working fine) The filesize bit is more of a bell/whistle.

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 569 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.