[Javascript] Image detection

Shawn Milo shawn.milo at gmail.com
Thu Apr 7 08:10:29 CDT 2005


I haven't tested this, but what if you changed your regex to:

"\.(jpg|gif|bmp|tif|png)$"

1. Added png support.
2. Assured that the match occurs in the file extension only.
   (comes at the end of the string, and after a period)


Shawn

On Apr 7, 2005 12:09 AM, Roland Neilands <rneilands at pulsemining.com.au> wrote:
> Terry,
> 
> > I don't know if this helps or, not, but I think Walter Zorn is doing it
> > somehow. Check out walterzorn.com
> Thanks, that is useful and I may use part of that instead of resize buttons, but perhaps some code would be clearer. This is what
> I've got so far:
> 
>        var objRegExp = new RegExp("jpg|gif|bmp|tif","i");
> 
>        if (objRegExp.test(filenames[imgno])) {
>          SDViewer.TheImage.src = filenames[imgno];
>        }
>        else {
>          SDViewer.location = filenames[imgno];
>        }
> 
> It's for an intranet app to display basically any item the user sees fit to link. Trouble is scanned documents or photos could be
> huge & they need to be able to shrink them to display or print the whole thing at once instead of a small corner. Preloading them
> would also be useful, but again I need to know first if it is an image.
> 
> Cheers,
> Roland
> 
> >
> > > Does anyone know of a simple way of detecting in Javascript if a given
> > > file is an image or not?
> > >
> > > I need to decide whether to load it into an <img> tag and provide
> > > resize buttons or not.
> > > Is checking a list of files extensions the only way?
> > >
> > > Regards,
> > > Roland
> > >
> > >
> > > _______________________________________________
> > > Javascript mailing list
> > > Javascript at LaTech.edu
> > > https://lists.LaTech.edu/mailman/listinfo/javascript
> > >
> >
> > _______________________________________________
> > Javascript mailing list
> > Javascript at LaTech.edu
> > https://lists.LaTech.edu/mailman/listinfo/javascript
> >
> 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
> 


-- 
Voicemail any time at:
206-666-MILO



More information about the Javascript mailing list