當前位置:首頁 » 編程語言 » php獲取圖片的類型

php獲取圖片的類型

發布時間: 2025-03-26 12:57:10

php取得.webp格式圖片尺寸

試試這個看看

<?php
$im=imagecreatefromwebp('http://7xjkan.com1.z0.glb.clouddn.com/undefined.webp');

//以100%的質量轉換成jpeg格式
imagejpeg($im,'./temp.jpeg',100);

$temp=getimagesize('temp.jpeg');
print_r($temp);

⑵ php 在多個上傳圖片時 怎麼獲取 要上傳的圖片寬高

分兩個部分,一個是「多個圖片」,一個是獲取圖片的寬、高。
第一個用循環做到,也就是用for、foreach之類的東西遍歷你從頁面中得到的圖片數組
下一步用getimagesize()函數獲得圖片的信息。
此函數在php手冊里有解釋:圖像生成與處理→GD→GD and image函數里。
此函數返回的結果如下:
返回一個具有四個單元的數組。索引 0 包含圖像寬度的像素值,索引 1 包含圖像高度的像素值。索引 2 是圖像類型的標記:1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP,7 = TIFF(intel byte order),8 = TIFF(motorola byte order),9 = JPC,10 = JP2,11 = JPX,12 = JB2,13 = SWC,14 = IFF,15 = WBMP,16 = XBM。這些標記與 PHP 4.3.0 新加的 IMAGETYPE 常量對應。索引 3 是文本字元串,內容為「height="yyy" width="xxx"」,可直接用於 IMG 標記。

⑶ PHP上傳圖片時,如何exif_read_data獲取exif

php獲取

圖片的exif信息,php自帶一個exif_read_data函數可以用來讀取圖片的exif信息,代碼來自php手冊:
<?php
echo "test1.jpg:<br /> ";
$exif = exif_read_data('tests/test1.jpg', 'IFD0');
echo $exif===false ? "No header data found.<br /> " : "Image contains headers<br /> ";
$exif = exif_read_data('tests/test2.jpg', 0, true);
echo "test2.jpg:<br /> ";
foreach ($exif as $key => $section) {
foreach ($section as $name => $val) {
echo "$key.$name: $val<br /> ";
}
}
?>

輸出結果如下

test1.jpg:
Noheaderdatafound.
test2.jpg:
FILE.FileName:test2.jpg
FILE.FileDateTime:1017666176
FILE.FileSize:1240
FILE.FileType:2
FILE.SectionsFound:ANY_TAG,IFD0,THUMBNAIL,COMMENT
COMPUTED.html:
COMPUTED.Height:1
COMPUTED.Width:1
COMPUTED.IsColor:1
COMPUTED.ByteOrderMotorola:1
COMPUTED.UserComment:Exiftestimage.
COMPUTED.UserCommentEncoding:ASCII
COMPUTED.Copyright:Photo(c)M.Boerger,EditedbyM.Boerger.
COMPUTED.Copyright.Photographer:Photo(c)M.Boerger
COMPUTED.Copyright.Editor:EditedbyM.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

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

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


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

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

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


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

<?
/**
*獲取圖象信息的函數
*一個全面獲取圖象信息的函數
*@accesspublic
*@paramstring$img圖片路徑
*@returnarray
*/
functionGetImageInfoVal($ImageInfo,$val_arr){
$InfoVal="未知";
foreach($val_arras$name=>$val){
if($name==$ImageInfo){
$InfoVal=&$val;
break;
}
}
return$InfoVal;
}
functionGetImageInfo($img){
$imgtype=array("","GIF","JPG","PNG","SWF","PSD","BMP","TIFF(intelbyteorder)","TIFF(motorolabyteorder)","JPC","JP2","JPX","JB2","SWC","IFF","WBMP","XBM");
$Orientation=array("","topleftside","toprightside","bottomrightside","bottomleftside","leftsidetop","rightsidetop","rightsidebottom","leftsidebottom");
$ResolutionUnit=array("","","英寸","厘米");
$YCbCrPositioning=array("","thecenterofpixelarray","thedatumpoint");
$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"=>"flashdidnotfire",
"1"=>"flashfired",
"5"=>"",
"7"=>"",
);

$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-dH: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],
/*
.
UnitisAPEX.
ToconvertthisvaluetoordinaryF-number(F-stop),
calculatethisvalue'spowerofroot2(=1.4142).
Forexample,iftheApertureValueis'5',F-numberispow(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]],
/*
Brightnessoftakensubject,unitisAPEX.TocalculateExposure(Ev)fromBrigtnessValue(Bv),youmustaddSensitivityValue(Sv).
Ev=Bv+SvSv=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",
/*
Storesusercomment.Thistagallowstousetwo-bytecharactercodeorunicode..'JIS'isaJapanesecharactercode(knownasKanji).
'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?"digitalstillcamera":"unknown"),
"場景類型"=>(bin2hex($exif[EXIF][SceneType])==0x01?"Adirectlyphotographedimage":"unknown"),
"縮略圖文件格式"=>$exif[COMPUTED][Thumbnail.FileType],
"縮略圖Mime格式"=>$exif[COMPUTED][Thumbnail.MimeType]
);
}
return$new_img_info;
}

$innerhtml="";
$exif=GetImageInfo($_GET['img']);
$innerhtml.="<TABLE>";

foreach($exifas$name=>$val){
$innerhtml.="<TR><TD>{$name}</TD><TD>{$val}</TD></TR>";
}

$innerhtml.="<TR><TDcolspan="2">";
if($_GET['img']){
$image=exif_thumbnail($_GET['img']);
}else{
$image=false;
}
if($image!==false){
$innerhtml.="<imgsrc="thumbnail.php?img=".$_GET['img']."">";
}else{
//nothumbnailavailable,handletheerrorhere
$innerhtml.="Nothumbnailavailable";
}

$innerhtml.="</TD></TR></TABLE>";
?>
<html>
<head>
<title>圖片信息</title>
<metahttp-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獲取圖片解析度 顏色模式函數

$img_info = getimagesize('a.jpg');
print_r($img_info);

索引 0 包含圖像寬度的像素值,索引 1 包含圖像高度的像素值。索引 2 是圖像類型的標記:1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP,7 = TIFF(intel byte order),8 = TIFF(motorola byte order),9 = JPC,10 = JP2,11 = JPX,12 = JB2,13 = SWC,14 = IFF,15 = WBMP,16 = XBM。

channels 和 bits。channels 對於 RGB 圖像其值為 3,對於 CMYK 圖像其值為 4。bits 是每種顏色的位數。

⑹ php怎麼實現根據圖片搜索圖片功能

php愛好者 們很對php開發的追求是永不止步的,今天偶然想起來了 發下
php怎麼實現相似圖片的搜索呢?
其中的原理來解釋下
1、縮小尺寸。將圖片縮小到8×8的尺寸,總共64個像素。這一步的作用是去除圖片的細節,只保留結構、明暗等基本信息,摒棄不同尺寸、比例帶來的圖片差異。
2、簡化色彩。將縮小後的圖片,轉為64級灰度。也就是說,所有像素點總共只有64種顏色。
3、計算平均值。計算所有64個像素的灰度平均值。
4、比較像素的灰度。將每個像素的灰度,與平均值進行比較。大於或等於平均值,記為1;小於平均值,記為0。
5、計算哈希值。將上一步的比較結果,組合在一起,就構成了一個64位的整數,這就是這張圖片的指紋。組合的次序並不重要,只要保證所有圖片都採用同樣次序就行了。得到指紋以後,就可以對比不同的圖片,看看64位中有多少位是不一樣的。
使用代碼
hash($f);
}
return $isString ? $result[0] : $result;
}
public function checkIsSimilarImg($imgHash, $otherImgHash){
if (file_exists($imgHash) && file_exists($otherImgHash)){
$imgHash = $this->run($imgHash);
$otherImgHash = $this->run($otherImgHash);
}
if (strlen($imgHash) !== strlen($otherImgHash)) return false;
$count = 0;
$len = strlen($imgHash);
for($i=0;$i<$len;$i++){
if ($imgHash{$i} !== $otherImgHash{$i}){
$count++;
}
}
return $count <= (5 * $rate * $rate) ? true : false;
}
public function hash($file){
if (!file_exists($file)){
return false;
}
$height = 8 * $this->rate;
$width = 8 * $this->rate;
$img = imagecreatetruecolor($width, $height);
list($w, $h) = getimagesize($file);
$source = $this->createImg($file);
imageresampled($img, $source, 0, 0, 0, 0, $width, $height, $w, $h);
$value = $this->getHashValue($img);
imagedestroy($img);
return $value;
}
public function getHashValue($img){
$width = imagesx($img);
$height = imagesy($img);
$total = 0;
$array = array();
for ($y=0;$y<$height;$y++){
for ($x=0;$x<$width;$x++){
$gray = ( imagecolorat($img, $x, $y) >> 8 ) & 0xFF;
if (!is_array($array[$y])){
$array[$y] = array();
}
$array[$y][$x] = $gray;
$total += $gray;
}
}
$average = intval($total / (64 * $this->rate * $this->rate));
$result = '';
for ($y=0;$y<$height;$y++){
for ($x=0;$x<$width;$x++){
if ($array[$y][$x] >= $average){
$result .= '1';
}else{
$result .= '0';
}
}
}
return $result;
}
public function createImg($file){
$ext = $this->getFileExt($file);
if ($ext === 'jpeg') $ext = 'jpg';
$img = null;
switch ($ext){
case 'png' : $img = imagecreatefrompng($file);break;
case 'jpg' : $img = imagecreatefromjpeg($file);break;
case 'gif' : $img = imagecreatefromgif($file);
}
return $img;
}
public function getFileExt($file){
$infos = explode('.', $file);
$ext = strtolower($infos[count($infos) - 1]);
return $ext;
}
}
調用方式如下:
require_once "Imghash.class.php";
$instance = ImgHash::getInstance();
$result = $instance->checkIsSimilarImg('chenyin/IMG_3214.png', 'chenyin/IMG_3212.JPG');
如果$result值為true, 則表明2個圖片相似,否則不相似。

熱點內容
如何編譯游戲腳本 發布:2025-03-29 15:59:06 瀏覽:381
道教源碼 發布:2025-03-29 15:56:35 瀏覽:935
希捷硬碟怎麼看緩存 發布:2025-03-29 15:55:11 瀏覽:243
音樂存儲方式 發布:2025-03-29 15:54:19 瀏覽:843
pythonbat 發布:2025-03-29 15:45:21 瀏覽:551
我的世界手機伺服器版 發布:2025-03-29 15:44:01 瀏覽:471
我的王朝自動腳本 發布:2025-03-29 15:43:28 瀏覽:225
電信寬頻的密碼怎麼改密碼 發布:2025-03-29 15:18:42 瀏覽:603
linux刪除ftp伺服器 發布:2025-03-29 15:08:10 瀏覽:248
怎麼在伺服器裡面設置多個ip 發布:2025-03-29 15:05:14 瀏覽:113