php中幾個簡單圖片判斷函數

來源:互聯網
上載者:User

int exif_imagetype ( string $filename )
1 imagetype_gif
2 imagetype_jpeg
3 imagetype_png
4 imagetype_swf
5 imagetype_ps教程d
6 imagetype_bmp
7 imagetype_tiff_ii (intel byte order)
8 imagetype_tiff_mm (motorola byte order) 
9 imagetype_jpc
10 imagetype_jp2
11 imagetype_jpx
12 imagetype_jb2
13 imagetype_swc
14 imagetype_iff
15 imagetype_wbmp
16 imagetype_xbm

*/
$img="image.gif";          //定義檔案
if(exif_imagetype($img)!=imagetype_gif)     //判斷檔案類型
{
  echo "指定的圖片不是gif圖片";       //輸出結果
}
else
{
  echo "指定的圖片是gif圖片";
}

/*
array exif_read_data ( string $filename [, string $sections = null [, bool $arrays = false [, bool $thumbnail = false ]]] )

*/

echo "test1.jpg:<br/>n";         //輸出檔案名
$exif=exif_read_data('tests/test1.jpg','ifd0');     //讀取檔案1資訊
             //根據結果判斷
echo $exif===false ? "no header data found.<br/>n":"image contains headers<br/>n";
$exif=exif_read_data('tests/test2.jpg',0,true);     //讀取檔案2資訊
echo "test2.jpg:<br/>n";         //輸出檔案名
foreach($exif as $key=>$section)       //迴圈讀取資訊
{
  foreach($section as $name=>$val)
  {
    echo "$key.$name:$val<br/>n";
  }
}
/*
test1.jpg:
no header data found.
test2.jpg:
file.filename: test2.jpg
file.filedatetime: 1017666176
file.filesize: 1240
file.filetype: 2
file.sectionsfound: any_tag, ifd0, thumbnail, comment
computed.html: width="1" height="1"
computed.height: 1
computed.width: 1
computed.iscolor: 1
computed.byteordermotorola: 1
computed.usercomment: exif test image.
computed.usercommentencoding: ascii
computed.copyright: photo (c) m.boerger, edited by m.boerger.
computed.copyright.photographer: photo (c) m.boerger
computed.copyright.editor: edited by m.boerger.
ifd0.copyright: photo (c) m.boerger
ifd0.usercomment: ascii
thumbnail.jpeginterchangeformat: 134
thumbnail.jpeginterchangeformatlength: 523
comment.0: comment #1.
comment.1: comment #2.
comment.2: comment #3end
thumbnail.jpeginterchangeformat: 134
thumbnail.thumbnail.height: 1
thumbnail.thumbnail.height: 1


//*/

$index="1";          //定義索引
$string=exif_tagname($index);       //獲得映像索引的頭資訊
echo $string;          //輸出結果

//

if(array_key_exists('file',$_request))
{
  $image=exif_thumbnail($_request['file'],$width,$height,$type);  //取得檔案的縮圖
}
else              //如果數組不存在相應的索引值
{
  $image=false;           //返回錯誤
}
if($image!==false)           //如果返回true
{
  header("content-type:".image_type_to_mime_type($type));   //發送標頭檔
  echo $image;           //輸出縮圖
  exit;             //結束php教程代碼
}
else              //如果返回錯誤
{
  echo "no thumbnail available";        //輸出資訊
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.