《PHP學習:php圖片處理函數獲取類型及擴展名實例》要點:
本文介紹了PHP學習:php圖片處理函數獲取類型及擴展名實例,希望對您有用。如果有疑問,可以聯系我們。
本文實例講述了php圖片處理函數獲取類型及擴展名的辦法.分享給大家供大家參考.PHP教程
具體實現代碼如下: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程序設計有所贊助.PHP教程
維易PHP培訓學院每天發布《PHP學習:php圖片處理函數獲取類型及擴展名實例》等實戰技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養人才。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/13889.html