JS get the original size of the picture

Source: Internet
Author: User

First, new naturalwidth and Naturalheight attributes in HTML5

In HTML 5, the new two attributes are added to determine the width and height of the image, respectively, the Naturalwidth and Naturalheight properties,

Examples are as follows:

var // Real picture width var // true real picture height

The premise is that the images must be fully downloaded to the client browser to be judged, and currently available in IE 9,firefox, Chrome, Safari and opera.


Second, if it is not supported version of the browser, it can be judged by the traditional method

examples are as follows:

varMyImage = document.getElementById ("MyImage");if(typeofMyimage.naturalwidth = = "undefined") {//IE 6/7/8    vari =NewImage (); I.SRC=myimage.src; varRW =I.width; varRH =i.height;}Else{//HTML5 Browsers    varRW =Myimage.naturalwidth; varRH =myimage.naturalheight;}

JS get the original size of the picture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.