笨笨啊 发表于 2005-10-24 02:51

〖原创〗〖PW小hack〗——控制选择头像时框的图片体积限制

请在注册时,或资料时选择头像图片,看效果

如果头像图片原本的宽度和高于小于指定值,则不会限制
如果大于指定值,则限制其为我们指定的值,以同比例缩放

代码如下

打开template\wind\profile.htm
找到
function showimage(imgpath,value)
{
    if(value!= '') {   
    document.images.useravatars.src=imgpath+'/face/'+value;
    } else{
    document.images.useravatars.src=imgpath+'/face/none.gif';
    }
}

替换为

function showimage(imgpath,value)
{
var mywidth,myheight;

mywidth=120; //在这里控制所能显示的图片最大尺寸,这个是宽,下面那个是长
myheight=120;

    if(value!= '') {   
    document.images.useravatars.src=imgpath+'/face/'+value;
    if (document.images.useravatars.width>mywidth)
    {
      document.images.useravatars.width=mywidth;
      document.images.useravatars.height=document.images.useravatars.height*mywidth/document.images.useravatars.width;
    }
    if (document.images.useravatars.height>myheight)
    {
      document.images.useravatars.height=myheight;
      document.images.useravatars.width=document.images.useravatars.width*myheight/document.images.useravatars.height;

    }

    } else{
    document.images.useravatars.src=imgpath+'/face/none.gif';
    }
}

同理,打开register.htm,也是找到
function showimage(imgpath,value)
{
    if(value!= '') {   
    document.images.useravatars.src=imgpath+'/face/'+value;
    } else{
    document.images.useravatars.src=imgpath+'/face/none.gif';
    }
}
替换为
function showimage(imgpath,value)
{
var mywidth,myheight;

mywidth=120; //在这里控制所能显示的图片最大尺寸,这个是宽,下面那个是长
myheight=120;

    if(value!= '') {   
    document.images.useravatars.src=imgpath+'/face/'+value;
    if (document.images.useravatars.width>mywidth)
    {
      document.images.useravatars.width=mywidth;
      document.images.useravatars.height=document.images.useravatars.height*mywidth/document.images.useravatars.width;
    }
    if (document.images.useravatars.height>myheight)
    {
      document.images.useravatars.height=myheight;
      document.images.useravatars.width=document.images.useravatars.width*myheight/document.images.useravatars.height;

    }

    } else{
    document.images.useravatars.src=imgpath+'/face/none.gif';
    }
}

Ok,完工~其实就是修改了其自带的showimage函数,加了长和宽的判断而矣:)嘻嘻

LovGate 发表于 2005-10-24 06:22

不错,收藏

笨笨啊 发表于 2005-10-24 11:59

要和那个头像选择的整合,昨天太困了先睡了,嘻嘻
所以还没上传,今天完善一下再上传
页: [1]
查看完整版本: 〖原创〗〖PW小hack〗——控制选择头像时框的图片体积限制