首页 > php代码 > php 获取图片尺寸

php 获取图片尺寸

<?php
    $arr=getimagesize("images/album_01.gif"); 
    echo $arr[3];
    $strarr=explode('"',$arr[3]);
    echo $strarr[1];
?>

<HTML> 

<HEAD> 

<TITLE>演示图片等比例缩小</TITLE> 

<script> 

function Wa_SetImgAutoSize(img) {
    //var img=document.all.img1;//获取图片
    var MaxWidth = 200; //设置图片宽度界限
    var MaxHeight = 100; //设置图片高度界限
    var HeightWidth = img.offsetHeight / img.offsetWidth; //设置高宽比
    var WidthHeight = img.offsetWidth / img.offsetHeight; //设置宽高比
    alert("test" + img.offsetHeight + img.fileSize);
    if (img.offsetHeight > 1)
        alert(img.offsetHeight);
    if (img.readyState != "complete") {
        return false; //确保图片完全加载
    }
    if (img.offsetWidth > MaxWidth) {
        img.width = MaxWidth;
        img.height = MaxWidth * HeightWidth;
    }
    if (img.offsetHeight > MaxHeight) {
        img.height = MaxHeight;
        img.width = MaxHeight * WidthHeight;
    }
}
function CheckImg(img) {
    var message = "";
    var MaxWidth = 1; //设置图片宽度界限
    var MaxHeight = 1; //设置图片高度界限
    if (img.readyState != "complete") {
        return false; //确保图片完全加载
    }
    if (img.offsetHeight > MaxHeight)
        message += "r高度超额:" + img.offsetHeight;
    if (img.offsetWidth > MaxWidth)
        message += "r宽度超额:" + img.offsetWidth;
    if (message != "")
        alert(message);
}

</script> 

</HEAD> 

<BODY> 

<img src="images/frequency.gif" border=0 id="img1" onload="CheckImg(this);"> 

<br> 

<input id="inp" type="file" onpropertychange="img1.src=this.value;"> 

</BODY> 

</HTML>

 


教程地址:http://www.phprm.com/code/10230eb5f9466f092a16b425dd7a8062.html

欢迎转载!但请带上文章地址^^

标签:none

发表留言