Znalezione kiedyś w sieci:
<script type="text/javascript"> <!--
// Begin
/* This script and many more are available free online at
The JavaScript Source!! <a href="http://javascript.internet.com" target="_blank">http://javascript.internet.com</a>
Created by: Abraham Joffe :: <a href="http://www.abrahamjoffe.com.au/" target="_blank">http://www.abrahamjoffe.com.au/</a> */
/***** CUSTOMIZE THESE VARIABLES *****/
// width to resize large images to
var maxWidth = 500;
// height to resize large images to
var maxHeight = 500;
// valid file types
var fileTypes = ["bmp", "gif", "png", "jpg", "jpeg"];
// the id of the <strong class="highlight">preview</strong> <strong class="highlight">image</strong> tag
var outImage = "previewField";
// what to display when the <strong class="highlight">image</strong> is not valid
var defaultPic = "spacer.gif";
/***** DO NOT EDIT BELOW *****/
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) {
//Obtenemos los datos de la imagen de firefox
try {
globalPic.src = what.files[0].getAsDataURL();
}
catch (err) {
globalPic.src = source;
}
}
else {
globalPic.src = defaultPic;
alert("ESTA NO ES UNA IMAGEN VALIDA por favor escoge una imagen de tipo:nn" + fileTypes.join(", "));
}
setTimeout("applyChanges()", 200);
}
var globalPic;
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 -->
<p>Pre-veiw pic from your drive
</p> <input type="file" id="picField" onchange="preview(this)"> <img alt="Graphic will preview here" id="previewField" src="http://i14.photobucket.com/ssalbums/a345/Instar/eye_search_e0.gif">