以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  上传的图片,只需要一处宽高相等,下面的代码怎么改?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=153662)

--  作者:zhangjian222200
--  发布时间:2020/8/18 16:28:00
--  上传的图片,只需要一处宽高相等,下面的代码怎么改?
1.页面代码
With wb.AddInputGroup("form1","ipg2","物品详图") 
    With.AddUploader("up4","",True) \'这儿需要所有up4图片宽高相等
        .Accept = "image/*"
        .AllowDelete = True \'允许用户删除图片
        .AllowAdd = True
        .Incremental = True \'允许重复选择文件或连续拍照
        .ScaleWidth = 400 \'自动压缩图片宽度为400个像素,高度等比例压缩
    End With
End With

2.weui文件:
function previewFile3(){
var images=[];
var glr=document.getElementById(this.id+\'_gallery\');
var thumbs = document.getElementById(this.id +"_thumbnails");
if (glr.attributes["data-images"].value){
images=glr.attributes["data-images"].value.split("|");
}
if (!this.nextindex){this.nextindex=0;}
var upd = this;
for(var i=0;i<this.files.length;i++){
var Files = this.Files;
var reader = new FileReader();
var ext = this.files[i].name;
ext = ext.substring(ext.lastIndexOf(".")+1).toLowerCase();
if(ext.substring(0,8)==\'image%3a\'){ext=\'jpg\'}
reader.Extension = ext;
reader.FileName = this.files[i].name;
switch(ext){
case "jpg": case "jpeg":case "png":case "gif":case "bmp":case "wmf":
reader.onload=function(e){
var img= new Image();
var red = e.target;
img.onload= function(g){

//alert(img.width)
//alert(img.height)
if(img.width<>img.height){ //如果这样写,就会要求所有图片宽高相等,但是我只需要上面的一处宽高相等即可,应该怎么处理?
      alert("图片宽高必须相等");
      return;
}
这里的用法是之前官方答复的
http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&replyID=764426&ID=112908&skin=1

var canvas = document.createElement(\'canvas\'); 
var ctx = canvas.getContext(\'2d\');
var w=-1, h=-1,x=0,y=0;
if (upd.hasAttribute("data-scalewidth")){w = upd.attributes["data-scalewidth"].value;}
if (upd.hasAttribute("data-scaleheight")){h = upd.attributes["data-scaleheight"].value;}
if(w>0 && h<=0){h=w/img.width * img.height;}
else if(w<=0 && h >0){w=h/img.height * img.width;}
else if(w<=0 && h <=0){w=img.width; h=img.height;}
canvas.width = w; 
canvas.height = h;
if (upd.hasAttribute("data-rotate")){
var rotate = upd.attributes["data-rotate"].value;
if (rotate ==1){
canvas.width = h; 
canvas.height = w;
y=-h;
ctx.rotate(90 * Math.PI/ 180);
}
else if (rotate ==2){
canvas.width = w; 
canvas.height = h;
x=-w;
y=-h;
ctx.rotate(180 * Math.PI/ 180);
}
else if (rotate ==3){
canvas.width = h; 
canvas.height = w;
x=-w;
ctx.rotate(270 * Math.PI/ 180);
}
}
ctx.drawImage(img, x, y, w, h); 
if(red.Extension == \'jpg\' || red.Extension == \'jpeg\'){var base64Data = canvas.toDataURL(\'image/jpeg\');}
else{var base64Data = canvas.toDataURL(\'image/png\');}
var nid =upd.id + "_thumb_" + upd.nextindex.toString()
thumbs.insertAdjacentHTML("beforeEnd","<li data-gid=\'"+ upd.id + "_gallery\'" +
" data-image=\'" + nid + "\'" + " id=\'" + nid + "\'" +
" class=\'weui_uploader_file\' temp style=\'background-image:url(" + base64Data + ")\'></li>");
images[images.length]="\'"+ nid +"\'";
glr.attributes["data-images"].value=images.join(\'|\');
upd.nextindex = upd.nextindex +1;
Files[Files.length] = {blobFile:red.FileName,data:base64toBlob(base64Data)};
}
img.src = e.target.result;  
}
reader.readAsDataURL(this.files[i]);
break;
default:
this.Files[this.Files.length]=this.files[i];
}
}
this.value=""
}
[此贴子已经被作者于2020/8/18 16:34:09编辑过]

--  作者:有点蓝
--  发布时间:2020/8/18 16:47:00
--  
给控件指定固定的名称,所有需要判断的都必须为""up宽高相等"开头,如:up宽高相等1、up宽高相等2、............

    With.AddUploader("up宽高相等4","",True) \'这儿需要所有up4图片宽高相等
--------------

//如果控件名称包含"up宽高相等"
if(upd.id.indexOf("up宽高相等") != -1 && img.width<>img.height){ //如果这样写,就会要求所有图片宽高相等,但是我只需要上面的一处宽高相等即可,应该怎么处理?
      alert("图片宽高必须相等");
      return;
}