php The function of getimagesize is to determine the size of any image file and return the size of the image as well as the file type and a height/width text string that can be used in the IMG tag in an ordinary HTML file, using the syntax such as " getimagesize('xxx.jpg')".
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
What is the usage of php getimagesize?
The getimagesize() function will determine the size of any GIF, JPG, PNG, SWF, SWC, PSD, TIFF, BMP, IFF, JP2, JPX, JB2, JPC, XBM or WBMP image file and Returns the dimensions of the image along with the file type and a height/width text string that can be used in an IMG tag in a normal HTML file.
Detailed explanation of the getimagesize method of php
The getimagesize method can view the detailed information of the image, as follows:
> print_r(getimagesize('mnjpg.jpg')); Array ( [0] => 2250 // 宽 [1] => 1500 // 高 [2] => 3 // 类型 [3] => width="2250" height="1500" [bits] => 8 [mime] => image/png )
Image type description
$imageTypeArray = array( 0 => 'UNKNOWN', 1 => 'GIF', 2 => 'JPEG', 3 => 'PNG', 4 => 'SWF', 5 => 'PSD', 6 => 'BMP', 7 => 'TIFF_II', 8 => 'TIFF_MM', 9 => 'JPC', 10 => 'JP2', 11 => 'JPX', 12 => 'JB2', 13 => 'SWC', 14 => 'IFF', 15 => 'WBMP', 16 => 'XBM', 17 => 'ICO', 18 => 'COUNT' );
Image upload, as jpeg Type as an example
$old_image = imagecreatefromjpeg($image_url); $new_image = imagecreatetruecolor($width, $height); imagecopy($new_image, $old_image, 0, 0, $x1, $y1, $width, $height); ob_start(); imagejpeg($new_image); $contents = ob_get_contents(); ob_end_clean(); imagedestroy($old_image); imagedestroy($new_image); // 新图片上传到图片服务器 $url = 'xxx/upload'; $client = Apf_Http_CurlClient::getInstance(); $ret = $client->doPost($url, array('file' => base64_encode($contents)), array(), array(), 1000); $ret = json_decode($ret, true);
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What is the usage of php getimagesize. For more information, please follow other related articles on the PHP Chinese website!