php獲取圖像信息(php採集圖片)

本文目錄一覽:

如何用php調用圖片?

PHP調用?好的,如果是HTML的話很簡單(只需要img標記插入即可),那麼我回答一下PHP的載入吧,代碼如下:

// 設置圖片路徑

$path = ‘/tupian/1.jpg’;

// 獲取圖片信息

$imgInfo = getimagesize($path);

// 獲取圖片類型

$imgType = $imgInfo[2];

// 檢測圖片類型

switch ($imgType) {

    case 1: // gif

       // 採用gif方式載入

       $img = imagecreatefromgif($path);

       // 聲明文件為圖片類型

       header(‘Content-Type:image/gif;’);

       // 採用gif方式輸出

       imagegif($img);

       break;

    case 2: // jpg

       // 採用jpg方式載入

       $img = imagecreatefromjpeg($path);

       // 聲明文件為圖片類型

       header(‘Content-Type:image/jpeg;’);

       // 採用jpeg方式輸出

       imagejpeg($img);

       break;

    case 3: // png

       // 採用png方式載入

       $img = imagecreatefrompng($path);

       // 聲明文件為圖片類型

       header(‘Content-Type:image/png;’);

       // 採用png方式輸出

       imagepng($img);

       break;

    default:

       exit(‘圖片格式不支持!’);

}

// 銷毀圖片資源

imagedestroy($img);

// 刪除變數

unset($img);

以上若還有什麼不明白的,歡迎追問~

php怎麼讀取內容頁的圖片

一般不向資料庫插入圖片 而是插入圖片的src 通過src找到圖片然後顯示。

?php

session_start();

//array數組中放圖片的格式

$uptypes = array(“image/jpg”,”image/jpeg”,”image/png”,”image/pjpeg”,”image/gif”,”image/bmp”,”image/x-png”);

$files =$_FILES[“uppic”];

if($files[“size”]2097152){ //圖片大小判斷

echo “上傳圖片不能大於2M”;

echo “meta http-equiv=’REFRESH’ CONTENT=’1;URL=pic.php'”;

exit;

}

$ftype =$files[“type”];

if(!in_array($ftype,$uptypes)){ //圖片格式判斷

echo “上傳的圖片文件格式不正確”;

echo “meta http-equiv=’REFRESH’ CONTENT=’1;URL=pic.php'”;

}

$fname = $files[“tmp_name”]; //在伺服器臨時存儲名稱

$image_info = getimagesize($fname);

$name = $files[“name”];

$str_name = pathinfo($name); //以數組的形式返迴文件路勁的信息

$extname = strtolower($str_name[“extension”]); //把字元串改為小寫 extensiorn擴展名

$upload_dir = “upload/”; //upload文件夾

$file_name = date(“YmdHis”).rand(1000,9999).”.”.$extname;

$str_file = $upload_dir.$file_name; //文件目錄

//存入資料庫

$con=mysql_connect(“localhost”,”root”,””);

if(!$con){

die((“資料庫連接失敗”).mysql_error());

}

mysql_select_db(“mywork”,$con);

$sql=”update user set picpath=’$str_file’ where user_name=’$username'”; //將圖片地址插入資料庫mywork

mysql_query($sql,$con);

mysql_close($con);

if(!file_exists($upload_dir)){

mkdir($upload_dir); //創建目錄 成功則返回true 失敗則返回flase

}

if(!move_uploaded_file($files[“tmp_name”],$str_file)){ //將上傳的文件移動到新的目錄 要移動文件和文件新目錄 成功則返回true

echo “圖片上傳失敗”;

echo “meta http-equiv=’REFRESH’ CONTENT=’1;URL=插入失敗後希望跳轉的頁面”;

}

else{

//echo “img src=”.$str_file.””;

echo “圖片上傳成功”;

echo “meta http-equiv=’REFRESH’ CONTENT=’1;URL=插入成功希望挑戰的頁面”;

}

php怎麼獲取本地圖片信息

用glob很方便就可獲得。

$img = array(‘gif’,’png’,’jpg’);//所有圖片的後綴名

$dir = ‘data/’;//文件夾名稱

$pic = array();

foreach($img as $k=$v)

{

$pattern = $dir.’*.’.$v;

$all = glob($pattern);

$pic = array_merge($pic,$all);

}

foreach($pic as $p)

{

//分行分頁顯示代碼

}

如果和圖片是同一個文件夾,那要將

$dir = ‘data/’;//文件夾名稱

改成

$dir = ‘./’;//文件夾名稱

PHP如何讀取照片的exif信息實現代碼

先來了解什麼是圖片的Exif信息

Exif是一種圖象文件格式,它的數據存儲與JPEG格式是完全相同的。

實際上Exif格式就是在JPEG格式頭部插入了數碼照片的信息,包括拍攝時的光圈、快門、白平衡、ISO、焦距、日期時間等各種和拍攝條件以及相機品牌、型號、色彩編碼、拍攝時錄製的聲音以及全球定位系統(GPS)、縮略圖等。簡單地說,Exif=JPEG+拍攝參數。

因此,你可以利用任何可以查看JPEG文件的看圖軟體瀏覽Exif格式的照片,但並不是所有的圖形程序都能處理Exif信息。

具體代碼你可以參考下面的

?

/**

* 獲取圖象信息的函數

* 一個全面獲取圖象信息的函數

* @access public

* @param string $img 圖片路徑

* @return array

*/

function GetImageInfoVal($ImageInfo,$val_arr) {

  $InfoVal  =  “未知”;

  foreach($val_arr as $name=$val) {

    if ($name==$ImageInfo) {

      $InfoVal  =  $val;

      break;

    }

  }

  return $InfoVal;

}

function GetImageInfo($img) {

  $imgtype      =  array(“”, “GIF”, “JPG”, “PNG”, “SWF”, “PSD”, “BMP”, “TIFF(intel byte order)”, “TIFF(motorola byte order)”, “JPC”, “JP2”, “JPX”, “JB2”, “SWC”, “IFF”, “WBMP”, “XBM”);

  $Orientation    =  array(“”, “top left side”, “top right side”, “bottom right side”, “bottom left side”, “left side top”, “right side top”, “right side bottom”, “left side bottom”);

  $ResolutionUnit    =  array(“”, “”, “英寸”, “厘米”);

  $YCbCrPositioning  =  array(“”, “the center of pixel array”, “the datum point”);

  $ExposureProgram  =  array(“未定義”, “手動”, “標準程序”, “光圈先決”, “快門先決”, “景深先決”, “運動模式”, “肖像模式”, “風景模式”);

  $MeteringMode_arr  =  array(

    “0”    =  “未知”,

    “1”    =  “平均”,

    “2”    =  “中央重點平均測光”,

    “3”    =  “點測”,

    “4”    =  “分區”,

    “5”    =  “評估”,

    “6”    =  “局部”,

    “255”  =  “其他”

    );

  $Lightsource_arr  =  array(

    “0”    =  “未知”,

    “1”    =  “日光”,

    “2”    =  “熒光燈”,

    “3”    =  “鎢絲燈”,

    “10”  =  “閃光燈”,

    “17”  =  “標準燈光A”,

    “18”  =  “標準燈光B”,

    “19”  =  “標準燈光C”,

    “20”  =  “D55”,

    “21”  =  “D65”,

    “22”  =  “D75”,

    “255”  =  “其他”

    );

  $Flash_arr      =  array(

    “0”    =  “flash did not fire”,

    “1”    =  “flash fired”,

    “5”    =  “flash fired but strobe return light not detected”,

    “7”    =  “flash fired and strobe return light detected”,

    );

   

  $exif = exif_read_data ($img,”IFD0″);

  if ($exif===false) {

    $new_img_info  =  array (“文件信息”    =  “沒有圖片EXIF信息”);

  }

  else

  {

    $exif = exif_read_data ($img,0,true);

    $new_img_info  =  array (

      “文件信息”    =  “—————————–“,

      “文件名”    =  $exif[FILE][FileName],

      “文件類型”    =  $imgtype[$exif[FILE][FileType]],

      “文件格式”    =  $exif[FILE][MimeType],

      “文件大小”    =  $exif[FILE][FileSize],

      “時間戳”    =  date(“Y-m-d H:i:s”,$exif[FILE][FileDateTime]),

      “圖像信息”    =  “—————————–“,

      “圖片說明”    =  $exif[IFD0][ImageDescription],

      “製造商”    =  $exif[IFD0][Make],

      “型號”      =  $exif[IFD0][Model],

      “方向”      =  $Orientation[$exif[IFD0][Orientation]],

      “水平解析度”  =  $exif[IFD0][XResolution].$ResolutionUnit[$exif[IFD0][ResolutionUnit]],

      “垂直解析度”  =  $exif[IFD0][YResolution].$ResolutionUnit[$exif[IFD0][ResolutionUnit]],

      “創建軟體”    =  $exif[IFD0][Software],

      “修改時間”    =  $exif[IFD0][DateTime],

      “作者”      =  $exif[IFD0][Artist],

      “YCbCr位置控制”  =  $YCbCrPositioning[$exif[IFD0][YCbCrPositioning]],

      “版權”      =  $exif[IFD0][Copyright],

      “攝影版權”    =  $exif[COMPUTED][Copyright.Photographer],

      “編輯版權”    =  $exif[COMPUTED][Copyright.Editor],

      “拍攝信息”    =  “—————————–“,

      “Exif版本”    =  $exif[EXIF][ExifVersion],

      “FlashPix版本”  =  “Ver. “.number_format($exif[EXIF][FlashPixVersion]/100,2),

      “拍攝時間”    =  $exif[EXIF][DateTimeOriginal],

      “數字化時間”  =  $exif[EXIF][DateTimeDigitized],

      “拍攝解析度高”  =  $exif[COMPUTED][Height],

      “拍攝解析度寬”  =  $exif[COMPUTED][Width],

      /*

      The actual aperture value of lens when the image was taken.

      Unit is APEX.

      To convert this value to ordinary F-number(F-stop),

      calculate this value’s power of root 2 (=1.4142).

      For example, if the ApertureValue is ‘5’, F-number is pow(1.41425,5) = F5.6.

      */

      “光圈”      =  $exif[EXIF][ApertureValue],

      “快門速度”    =  $exif[EXIF][ShutterSpeedValue],

      “快門光圈”    =  $exif[COMPUTED][ApertureFNumber],

      “最大光圈值”  =  “F”.$exif[EXIF][MaxApertureValue],

      “曝光時間”    =  $exif[EXIF][ExposureTime],

      “F-Number”    =  $exif[EXIF][FNumber],

      “測光模式”    =  GetImageInfoVal($exif[EXIF][MeteringMode],$MeteringMode_arr),

      “光源”      =  GetImageInfoVal($exif[EXIF][LightSource], $Lightsource_arr),

      “閃光燈”    =  GetImageInfoVal($exif[EXIF][Flash], $Flash_arr),

      “曝光模式”    =  ($exif[EXIF][ExposureMode]==1?”手動”:”自動”),

      “白平衡”    =  ($exif[EXIF][WhiteBalance]==1?”手動”:”自動”),

      “曝光程序”    =  $ExposureProgram[$exif[EXIF][ExposureProgram]],

      /*

      Brightness of taken subject, unit is APEX. To calculate Exposure(Ev) from BrigtnessValue(Bv), you must add SensitivityValue(Sv).

      Ev=Bv+Sv  Sv=log((ISOSpeedRating/3.125),2)

      ISO100:Sv=5, ISO200:Sv=6, ISO400:Sv=7, ISO125:Sv=5.32. 

      */

      “曝光補償”    =  $exif[EXIF][ExposureBiasValue].”EV”,

      “ISO感光度”    =  $exif[EXIF][ISOSpeedRatings],

      “分量配置”    =  (bin2hex($exif[EXIF][ComponentsConfiguration])==”01020300″?”YCbCr”:”RGB”),//’0x04,0x05,0x06,0x00’=”RGB” ‘0x01,0x02,0x03,0x00’=”YCbCr”

      “圖像壓縮率”  =  $exif[EXIF][CompressedBitsPerPixel].”Bits/Pixel”,

      “對焦距離”    =  $exif[COMPUTED][FocusDistance].”m”,

      “焦距”      =  $exif[EXIF][FocalLength].”mm”,

      “等價35mm焦距”  =  $exif[EXIF][FocalLengthIn35mmFilm].”mm”,

      /*

      Stores user comment. This tag allows to use two-byte character code or unicode. First 8 bytes describe the character code. ‘JIS’ is a Japanese character code (known as Kanji).

      ‘0x41,0x53,0x43,0x49,0x49,0x00,0x00,0x00’:ASCII

      ‘0x4a,0x49,0x53,0x00,0x00,0x00,0x00,0x00’:JIS

      ‘0x55,0x4e,0x49,0x43,0x4f,0x44,0x45,0x00’:Unicode

      ‘0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00’:Undefined

      */

      “用戶注釋編碼”  =  $exif[COMPUTED][UserCommentEncoding],

      “用戶注釋”    =  $exif[COMPUTED][UserComment],

      “色彩空間”    =  ($exif[EXIF][ColorSpace]==1?”sRGB”:”Uncalibrated”),

      “Exif圖像寬度”  =  $exif[EXIF][ExifImageLength],

      “Exif圖像高度”  =  $exif[EXIF][ExifImageWidth],

      “文件來源”    =  (bin2hex($exif[EXIF][FileSource])==0x03?”digital still camera”:”unknown”),

      “場景類型”    =  (bin2hex($exif[EXIF][SceneType])==0x01?”A directly photographed image”:”unknown”),

      “縮略圖文件格式”  =  $exif[COMPUTED][Thumbnail.FileType],

      “縮略圖Mime格式”  =  $exif[COMPUTED][Thumbnail.MimeType]

    );

  }

  return $new_img_info;

}

 

$innerhtml  =  “”;

$exif  =  GetImageInfo($_GET[‘img’]);

$innerhtml  .=  “TABLE”;

 

foreach($exif as $name=$val) {

  $innerhtml  .=  “TRTD{$name}/TDTD{$val}/TD/TR”;

}

 

$innerhtml  .=  “TRTD colspan=\”2\””;

if ($_GET[‘img’]) {

  $image = exif_thumbnail($_GET[‘img’]);

} else {

  $image = false;

}

if ($image!==false) {

  $innerhtml  .=  “img src=\”thumbnail.php?img=”.$_GET[‘img’].”\””;

} else {

  // no thumbnail available, handle the error here

  $innerhtml  .=  “No thumbnail available”;

}

 

$innerhtml  .=  “/TD/TR/TABLE”;

?

html

head 

title圖片信息/title

meta http-equiv=”Content-Type” content=”text/html; charset=??????”

/head

body

SCRIPT

!–

//初始化內容值

parent.followTd?=$_GET[‘r_id’];?.innerHTML=’?=$innerhtml;?’;

//已讀取

parent.document.images.followImg?=$_GET[‘r_id’];?.loaded=’yes’;

/SCRIPT

/body

/html

php 讀取圖片並輸出

?php

header(‘Content-Type:image/png’);

$url = “”;//圖片鏈接

$ch = curl_init();

//Cookie:PHPSESSID=121b1127dcded8702c6a1e702c40eca4

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch,CURLOPT_COOKIE,’PHPSESSID=121b1127dcded8702c6a1e702c40eca4′);//如果不需要cookies就刪除這條語句

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);

curl_setopt($ch, CURLOPT_TIMEOUT,0);//忽略超時

curl_setopt($ch, CURLOPT_NOBODY, false);

$str = curl_exec($ch);

curl_close($ch);

原創文章,作者:簡單一點,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/127407.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
簡單一點的頭像簡單一點
上一篇 2024-10-03 23:15
下一篇 2024-10-03 23:15

相關推薦

  • PHP和Python哪個好找工作?

    PHP和Python都是非常流行的編程語言,它們被廣泛應用於不同領域的開發中。但是,在考慮擇業方向的時候,很多人都會有一個問題:PHP和Python哪個好找工作?這篇文章將從多個方…

    編程 2025-04-29
  • 如何在Java中拼接OBJ格式的文件並生成完整的圖像

    OBJ格式是一種用於表示3D對象的標準格式,通常由一組頂點、面和紋理映射坐標組成。在本文中,我們將討論如何將多個OBJ文件拼接在一起,生成一個完整的3D模型。 一、讀取OBJ文件 …

    編程 2025-04-29
  • 用Python繪製酷炫圖片

    在本篇文章中,我們將展示如何使用Python繪製酷炫的圖片。 一、安裝Python繪圖庫 在使用Python繪製圖片之前,我們需要先安裝Python繪圖庫。Python有很多繪圖庫…

    編程 2025-04-29
  • 如何實現圖像粘貼到蒙版

    本文將從多個方面介紹圖像粘貼到蒙版的實現方法。 一、創建蒙版 首先,在HTML中創建一個蒙版元素,用於接收要粘貼的圖片。 <div id=”mask” style=”widt…

    編程 2025-04-29
  • 使用axios獲取返回圖片

    使用axios獲取返回圖片是Web開發中很常見的需求。本文將介紹如何使用axios獲取返回圖片,並從多個方面進行詳細闡述。 一、安裝axios 使用axios獲取返回圖片前,首先需…

    編程 2025-04-29
  • Python 圖片轉表格

    本文將詳細介紹如何使用Python將圖片轉為表格。大家平時在處理一些資料的時候難免會遇到圖片轉表格的需求。比如從PDF文檔中提取表格等場景。當然,這個功能也可以通過手動複製、粘貼,…

    編程 2025-04-29
  • PHP怎麼接幣

    想要在自己的網站或應用中接受比特幣等加密貨幣的支付,就需要對該加密貨幣擁有一定的了解,並使用對應的API進行開發。本文將從多個方面詳細闡述如何使用PHP接受加密貨幣的支付。 一、環…

    編程 2025-04-29
  • Python緩存圖片的處理方式

    本文將從多個方面詳細闡述Python緩存圖片的處理方式,包括緩存原理、緩存框架、緩存策略、緩存更新和緩存清除等方面。 一、緩存原理 緩存是一種提高應用程序性能的技術,在網路應用中流…

    編程 2025-04-29
  • Python如何抓取圖片數據

    Python是一門強大的編程語言,能夠輕鬆地進行各種數據抓取與處理。抓取圖片數據是一個非常常見的需求。在這篇文章中,我們將從多個方面介紹Python如何抓取圖片數據。 一、使用ur…

    編程 2025-04-29
  • Java 監控介面返回信息報錯信息怎麼處理

    本文將從多個方面對 Java 監控介面返回信息報錯信息的處理方法進行詳細的闡述,其中包括如何捕獲異常、如何使用日誌輸出錯誤信息、以及如何通過異常處理機制解決報錯問題等等。以下是詳細…

    編程 2025-04-29

發表回復

登錄後才能評論