The first is the JS method, through the new Image object, set the Src property, and listen to the complete and onload events, the picture after the completion of loading the output width and height
function Checkpicurl (URL) {
var img = new Image ();
img.src = URL;
Img.onerror = function () {
Alert (name+ "picture failed to load, please check the URL is correct");
return false;
};
if (img.complete) {
Console.log (img.width+ "" +img.height);
}else{
Img.onload = function () {
Console.log (img.width+ "" +img.height);
Img.onload=null; Avoid repeated loading
}
}
}
Php Method:
The use of PHP is because of the need to put in a batch of data, the URL field value of the data is not tiled picture width and high information, and the demand is to record, so that the table from the recognition of the image is not the width of the data, and to obtain each image URL size information, in the update to the table. The Java implementation is relatively cumbersome, and PHP provides the getimagesize function, you can get local and network image size information, the function is described as follows:
GetImageSize: Get the picture's length and width.
Syntax: array getimagesize (string filename, array [imageinfo]);
return value: Array
Function type: Graphics processing
Content Description
This function can be used to obtain the height and width of GIF, JPEG and PNG three WWW slices, and it is not necessary to install GD library to use this function. The returned array has four elements. The first element of the returned array (index value 0) is the height of the picture, in pixels (pixel). The second element (index value 1) is the width of the picture. The third element (index value 2) is the file format of the picture, with a value of 1 in GIF format, 2 in jpeg/jpg format, and 3 in PNG format. The fourth element (index value 3) is the height and width of the picture string, Height=xxx width=yyy. The omitted parameter imageinfo is used to obtain some information about the picture, such as the APP13 mark of the IPTC (HTTP://WWW.XE.NET/IPTC), which can be added to the picture, and can be parsed using iptcparse ().
Usage examples
function Myimg ($imgfile) {
$size = getimagesize ($imgfile);
echo "";
}
Myimg ("Img/img1.gif");
Myimg ("Http://img02.sogoucdn.com/app/a/100520052/5a1f885e25b7af28822b14dc069a5f16");
?>
The above describes several ways to get the image size by URL: js and PHP, including the content, I hope the PHP tutorial interested in a friend helpful.