Home  >  Article  >  Backend Development  >  What is the usage of php getimagesize

What is the usage of php getimagesize

藏色散人
藏色散人Original
2021-11-10 09:56:301819browse

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')".

What is the usage of php getimagesize

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn