php Image Processing Function Acquisition Type and Extension Instance
- 2021-08-05 09:07:05
- OfStack
This paper describes the method of obtaining type and extension of php image processing function. Share it for your reference.
The specific implementation code is as follows:
image_type=image_type_to_mime_type(imagetype_png); // Get png Adj. mime Type
echo $image_type; // Output result
//
$file = '1.jpg';
$image = imagecreatefromjpeg($file);
header('content-type: ' . image_type_to_mime_type(imagetype_wbmp));
$fp=fopen($file,r);
fpassthru($fp);
image2wbmp($image,"1.bmp"); // output the stream directly
//image_type_to_extension. (php Tutorials 5). image_type_to_extension - Gets a file of image type Suffix ... warning. There is no document for this function at present
$file_ext=image_type_to_extension("1.jpg");
echo $file_ext;
//
$filename="1.jpg"; // Define an image file
$size=getimagesize($filename); // Gets the size of the image
$fp=fopen($filename,"rb"); // Open a file
if($size && $fp) // If open successfully
{
header("content-type: {$size['mime']}"); // Output file header information
fpassthru($fp); // Output file content
exit; // Abort operation
}
else
{
echo " File failed to open, or the specified file is not an image file "; // Output error message
}
I hope this article is helpful to everyone's PHP programming.