close

javascript 取得圖片長寬

function getImgSize(imgSrc) 

var newImg = new Image(); 
newImg.src = imgSrc; 
var height = newImg.height; 
var width = newImg.width; 
alert ('The image size is '+width+'*'+height); 

</script>

使用 
onclick="getImgSize('images/testout_r1_c2.jpg')"

 

使用到javascript的Image物件,用他的height和width屬性去求出長寬

下面有Image物件的內容

JavaScript Image Object

The JavaScript Image Object is a property of the document object.

Properties

  • border - The width of the border around the image in pixels.
  • complete - A boolean value which identifies whether an image is completely loaded yet.
  • height - The read only height of the image in pixels.
  • hspace - The read only amount of horizontal space to the left and right sides of the image.
  • lowsrc - The read or write string giving the URL of an alternate image for low resolution screen display.
  • name - The assigned name of the image.
  • prototype - Used for adding user-specified properties to the image.
  • src - The URL of the image to be displayed. It is a read/write string.
  • vspace - The read only vertical space above and below the image.
  • width - The read only width of the image in pixels.

Events

 

  • onAbort
  • onError
  • onLoad

--

轉自 http://kaohsing.blogspot.com/2010/03/javascript.html

http://www.comptechdoc.org/independent/web/cgi/javamanual/javaimage.html

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 dizzy03 的頭像
    dizzy03

    碎碎念

    dizzy03 發表在 痞客邦 留言(0) 人氣()