java上传图片前预览 控制图片尺寸大小 控制上传格式
2015-04-03 11:31
549 查看
原文:http://blog.sina.com.cn/s/blog_4d3d00180102v4yl.html
var maxH = 768;
var maxW = 1024;
function DrawImage(ImgD){
var preW = 300;
var preH = 400 ;
var image=new Image();
image.src=ImgD.src;
if(image.width > maxW || image.height > maxH){
alert("图片尺寸过大,请选择" + maxW + "*" + maxH + "的图片!");
return;
}
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= preW/preH){
if(image.width>preW){
ImgD.width=preW;
ImgD.height=(image.height*preW)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>preH){
ImgD.height=preH;
ImgD.width=(image.width*preH)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
function checkFormat(filePath) {
var i = filePath.lastIndexOf('.');
var len = filePath.length;
var str = filePath.substring(len,i+1);
var extName = "JPG,GIF,PNG,JPEG,BMP";
if(extName.indexOf(str.toUpperCase()) < 0) {
alert("请选择正确的图片文件!");
return false;
}
return true;
}
function FileChange(Value){
if(checkFormat(Value)){
flag=false;
document.getElementByIdx_x("uploadimage").width=10;
document.getElementByIdx_x("uploadimage").height=10;
document.getElementByIdx_x("uploadimage").alt="";
document.getElementByIdx_x("uploadimage").src=Value;
}
}
var maxH = 768;
var maxW = 1024;
function DrawImage(ImgD){
var preW = 300;
var preH = 400 ;
var image=new Image();
image.src=ImgD.src;
if(image.width > maxW || image.height > maxH){
alert("图片尺寸过大,请选择" + maxW + "*" + maxH + "的图片!");
return;
}
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= preW/preH){
if(image.width>preW){
ImgD.width=preW;
ImgD.height=(image.height*preW)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>preH){
ImgD.height=preH;
ImgD.width=(image.width*preH)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
function checkFormat(filePath) {
var i = filePath.lastIndexOf('.');
var len = filePath.length;
var str = filePath.substring(len,i+1);
var extName = "JPG,GIF,PNG,JPEG,BMP";
if(extName.indexOf(str.toUpperCase()) < 0) {
alert("请选择正确的图片文件!");
return false;
}
return true;
}
function FileChange(Value){
if(checkFormat(Value)){
flag=false;
document.getElementByIdx_x("uploadimage").width=10;
document.getElementByIdx_x("uploadimage").height=10;
document.getElementByIdx_x("uploadimage").alt="";
document.getElementByIdx_x("uploadimage").src=Value;
}
}
相关文章推荐
- 图片上传之前检查大小、尺寸、格式并预览的js代码
- 图片上传之前检查大小、尺寸、格式并预览(Validate the file size/file type/image size/ before upload)
- 图片上传之前检查大小、尺寸、格式并预览
- 上传图片预览、大小、格式控制
- jquery控制上传文件格式、大小以及图片预览功能
- 图片上传之前检查大小、尺寸、格式并预览的js代码
- 图片上传之前检查大小、尺寸、格式并预览
- UEditor控制上传图片的显示尺寸大小
- iOS 上传到AppStore上的icon尺寸和预览图片大小
- Javascript实现上传前对图片大小、格式的检查并预览
- 图片上传预览、图片大小验证、图片格式验证(本人亲自测试)
- ASP.NET上传图片,服务器端验证,宽度,高度,文件类型,尺寸,文件大小,图片上传,图片格式检查
- 兼容ie6、ie7、ie8 和FF的本地上传图片预览,并客户端判断文件大小和文件格式
- 上传预览,图片展示大小的控制
- neatbeans用js实现图片预览上传(自动控制图片大小)
- 上传图片时js验证图片大小、尺寸、格式
- js实现上传图片本地预览功能以及限制图片的文件大小和尺寸大小
- js上传图片进行预览、验证格式及尺寸
- js图片上传验证图片格式和大小尺寸
- 兼容ie6、ie7、ie8 和FF的本地上传图片预览,并客户端判断文件大小和文件格式