Home  >  Article  >  php教程  >  php图片处理函数获取类型及扩展名实例

php图片处理函数获取类型及扩展名实例

WBOY
WBOYOriginal
2016-06-06 20:17:101167browse

这篇文章主要介绍了php图片处理函数获取类型及扩展名的方法,包括image2wbmp、image_type_to_extension、image_type_to_mime_type等函数的具体使用,具有不错的借

本文实例讲述了php图片处理函数获取类型及扩展名的方法。分享给大家供大家参考。

具体实现代码如下:

复制代码 代码如下:

image_type=image_type_to_mime_type(imagetype_png);   //获取png的mime类型
echo $image_type;           //输出结果
//
 
$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教程 5). image_type_to_extension — 取得图像类型的文件 后缀 ... warning. 本函数暂无文档
 
$file_ext=image_type_to_extension("1.jpg");
echo $file_ext;
//
 
$filename="1.jpg";         //定义图像文件
$size=getimagesize($filename);      //获取图像的大小
$fp=fopen($filename,"rb");        //打开文件
if($size && $fp)          //如果成功打开
{
  header("content-type: {$size['mime']}");     //输出文件头信息
  fpassthru($fp);         //输出文件内容
  exit;           //中止操作
}
else
{
  echo "文件打开失败,,或者指定的不是图像文件";   //输出错误信息
}

希望本文所述对大家的PHP程序设计有所帮助。

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