『壹』 php如何讀取照片的exif信息實現代碼
<?php
/**
*讀取jpeg圖片的Exif信息
*$img為圖片路徑
*
*瓊台博客
*/
functiongetExif($img){
$exif=exif_read_data($img,'IFD0');
returnarray(
'文件名'=>$exif['FileName'],
'器材品牌'=>$exif['Make'],
'器材'=>$exif['Model'],
'快門'=>$exif['ExposureTime'],
'光圈'=>$exif['FNumber'],
'焦距'=>$exif['FocalLength'],
'感光度'=>$exif['ISOSpeedRatings']
);
}
讀取照片
<?php
$exifInfo=getExif('a.jpg');
echo'<pre>';
print_r($exifInfo);
echo'</pre>';
執行結果:
Array
(
[文件名]=>25556306.jpg
[器材品牌]=>NIKONCORPORATION
[器材]=>NIKOND3100
[快門]=>10/32000
[光圈]=>18/10
[焦距]=>350/10
[感光度]=>100
)
『貳』 php中如何調用資料庫中的圖片並且顯示到頁面
php是採用二進制形式存儲圖片及讀取顯示的,首先通過代碼創建數據表,然後上傳圖片伺服器再通過瀏覽器顯示,具體編程代碼舉例:
1、首先需要創建數據表,具體代碼如下圖所示。
『叄』 用PHP獲取鏈接及圖片路徑的方法
<?php
$str="Thisisatest.Thisisatest.Thisisa<ahref=http://link1.com><imgsrc=http://img1.jpg/></a>test.Thisisatest.Thisisatest. ".
"Thisisatest.Thisisatest.<ahref=http://link2.com><imgsrc=http://img2.jpg/></a>Thisisatest.Thisisatest.Thisisatest. ".
"<ahref=http://link3.com><imgsrc=http://img3.jpg/></a>";
$regex='/<as+href=(.*)s*><imgs+src=(.*)s*/></a>/';
$output=array();
if(preg_match_all($regex,$str,$matches)!==false){
if(isset($matches[1])&&isset($matches[2])){
$links=$matches[1];
$imgs=$matches[2];
foreach($linksas$key=>$link){
$img=isset($imgs[$key])?$imgs[$key]:'';
$output[]="<ahref="{$link}"><imgsrc="{$img}"/></a>";
}
}
}
var_mp($output);
『肆』 PHP怎麼讀取php所在文件夾下的圖片和mp3文件,並且顯示出來
<?php
$dir="./";//要獲取的目錄
echo"**********獲取目錄下所有文件和文件夾***********<hr/>";
//先判斷指定的路徑是不是一個文件夾
if(is_dir($dir)){
if($dh=opendir($dir)){
while(($file=readdir($dh))!=false){
if(getFileType($file)=="mp3"){
echo"mp3格式";
}
if(getFileType($file)=="jpg"||getFileType($file)=="png"||getFileType($file)=="gif"){
echo"圖片格式";
}
closedir($dh);
}
}
functiongetFileType($filename){
returnstrtolower(pathinfo($filename)['extension']);
}
?>
『伍』 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讀取圖片的路徑
你的代碼是遍歷$dir文件夾下面的文件,然後輸出成<img src=""/>,訪問伺服器上的圖片一般是網址+具體路徑,例如:localhost/public/logo.jpg,是指訪問網址根目錄下的public/logo.jpg文件,對應你這里的就是htdocs/public/logo.jpg
圖片的顯示大小可以設置img的width和heigth屬性,位置可以設置相應的css值,例如<img src="/public/logo.jpg" width="100px" heigth="100px" style="display:block;margin:0 auto">
『柒』 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 標記。