1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
   | // ImageUpload.js
 
 
/* **** CUSTOMIZE THESE VARIABLES **** */
 
  // width to resize large images to
var maxWidth=240;
  // height to resize large images to
var maxHeight=250;
  // valid file types
var fileTypes=["bmp","gif","png","jpg","jpeg"];
  // the id of the preview image tag
var outImage="previewField";
  // what to display when the image is not valid
var defaultPic="gifs/AffDefault.PNG";
 
/* **** DO NOT EDIT BELOW **** */
var globalPic;
 
function preview(what)
{
  var source=what.value;
  var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
 
  for (var i=0; i<fileTypes.length; i++) if (fileTypes[i]==ext) break;
 
 	globalPic = new Image();
 	if (i<fileTypes.length)
 	{
 		globalPic.src=source;
 	}
	else 
	{
		globalPic.src=defaultPic;
    	alert("THAT IS NOT A VALID IMAGE\nPlease load an image with an extention of one of the following:\n\n"+fileTypes.join(", "));
  	}
  setTimeout("applyChanges()",200);
}
 
function applyChanges()
{
  var field=document.getElementById(outImage);
  var x=parseInt(globalPic.width);
  var y=parseInt(globalPic.height);
 
  if (x>maxWidth) 
  {
    y*=maxWidth/x;
    x=maxWidth;
  }
  if (y>maxHeight) 
  {
    x*=maxHeight/y;
    y=maxHeight;
  }
 
  field.style.display=(x<1 || y<1)?"none":"";
  field.src=globalPic.src;
  field.width=x;
  field.height=y;
}
// End --> | 
Partager