Welcome to the Linux community forum and interact with 2 million technical staff. When we use PHP to develop a user center, the user's portrait upload function will certainly be available, or when developing other interaction functions to upload images, we need to know whether the images uploaded by users meet our requirements. Here we will share with you a simple way to obtain image attributes.
Welcome to the Linux community forum and interact with 2 million technical staff> when we are using PHP to develop a user center, users will certainly upload their portraits, or when developing other interaction functions to upload images, we need to know whether the images uploaded by users meet our requirements. Here we will share with you a simple way to obtain image attributes.
Welcome to the Linux community forum and interact with 2 million technicians>
When we use PHP to develop a user center, the user's portrait upload function will certainly be available, or when other interaction functions need to upload images, we all need to know whether the images uploaded by users meet our requirements. Here we will share with you a simple PHP user-defined function for retrieving image attributes, hoping to help you, this function was also written by a netizen on the Internet. It has been tested by UncleToo and has good results and is easy to use.
Code:
/**
* Obtain image information
*
* @ Param string $ image file name
*
* @ Return mixed
*/
Function getImageInfo ($ image ){
$ ImageInfo = getimagesize ($ image );
If ($ imageInfo! = FALSE ){
$ ImageType = strtolower (substr (image_type_to_extension ($ imageInfo [2]), 1 ));
$ ImageSize = filesize ($ image );
$ Info = array (
"Width" => $ imageInfo [0],
"Height" => $ imageInfo [1],
"Type" => $ imageType,
"Size" => $ imageSize,
"Mime" => $ imageInfo ['mime ']
);
Return $ info;
} Else {
Return FALSE;
}
}
?>
Call example:
1
2
3
4
$ Info = getImageInfo('123.jpg ');
Var_dump ($ info );
?>
Output result:
Array (5 ){
["Width"] =>
Int (614)
["Height"] =>
Int (850)
["Type"] =>
String (4) "jpeg"
["Size"] =>
Int (597066)
["Mime"] =>
String (10) "image/jpeg"
}
The output information is the same as the information displayed in the image below.
Image Information: