사이트 내 전체검색
PHP
[함수] 사진 카메라 정보 exif 클래스
로빈아빠
https://cmd.kr/php/867 URL이 복사되었습니다.

본문

php5 클래스 시리즈 <span style="background-color:YELLOW; color:RED;">exif</span>

사진에 등록된 카메라 및 정보 가져오기
read_<span style="background-color:YELLOW; color:RED;">exif</span>_data 가 안될 시 
getimagesize 로 기본 정보 맟 추출하기

<?php
define('_READ_<span style="background-color:YELLOW; color:RED;">EXIF</span>_ON_',1); # <span style="background-color:YELLOW; color:RED;">exif</span> 함수 설정됨
define('_READ_<span style="background-color:YELLOW; color:RED;">EXIF</span>_OFF_',2); # <span style="background-color:YELLOW; color:RED;">exif</span> 함수&nbsp; 활용 불가

class Image<span style="background-color:YELLOW; color:RED;">Exif</span> {
private $picture;
private $<span style="background-color:YELLOW; color:RED;">exif</span>mode = 1;
public function __construct($picture){
# 로컬 파인인지 체크
if(!file_exists($picture))
throw new ErrorReporter('',30);

# 함수 enable 체크
if(!function_exists(read_<span style="background-color:YELLOW; color:RED;">exif</span>_data))
$this-><span style="background-color:YELLOW; color:RED;">exif</span>mode = 2;
$this->picture = $picture;
}
# 파일 용량 체크
public function fileSize()
{
$result = '';
$size = filesize($this->picture);
if(!empty($size)){
$result = sprintf("%0.1f KB", ($size/1024));
if($r>1024){
$result = sprintf("%0.1f MB", ($r/1024)); //수점 이하가 0.5 는 1로 반올림한다.
}
}
return $result;
}
# <span style="background-color:YELLOW; color:RED;">exif</span> OFF 일때 이미지 기본 정보만 돌려준다
public function getImageInfo()
{
$args = array();
$size = @getimagesize($this->filename);
# 파일정보
if($size){
$args = array(
'filesize' => self::fileSize(), // 파일사이즈
#'datetime' => '', // 촬영일자
'filewh' => ($size[0]) ? $size[0].' x '.$size[1]: '', // 사진사이즈
#'flashonoff'=> ''
);
}
return $args;
}

# 사진 정보 추출하기
public function set<span style="background-color:YELLOW; color:RED;">Exif</span>()
{
$<span style="background-color:YELLOW; color:RED;">exif</span> = @read_<span style="background-color:YELLOW; color:RED;">exif</span>_data($this->picture);
if($<span style="background-color:YELLOW; color:RED;">exif</span> ===false)
throw new ErrorReporter('');
# 플래시 사용여부
$flash = '';
switch($<span style="background-color:YELLOW; color:RED;">exif</span>['FlashUsed']){
case 0 : $flash = 'OFF'; break;
case 1 : $flash = 'ON'; break;
}
## 카메라 모델
$cameramodel = '';
if($<span style="background-color:YELLOW; color:RED;">exif</span>['Make']) $cameramodel = str_replace('CORPORATION','',$<span style="background-color:YELLOW; color:RED;">exif</span>['Make']).' '; // 제조사
if($<span style="background-color:YELLOW; color:RED;">exif</span>['Model']) $cameramodel.= $<span style="background-color:YELLOW; color:RED;">exif</span>['Model']; // 제품명

## 촬영거리
$focusdistance = '';
if($<span style="background-color:YELLOW; color:RED;">exif</span>['FocusDistance']){
$tmpdistance = explode('/',$<span style="background-color:YELLOW; color:RED;">exif</span>['FocusDistance']);
$focusdistance = ($tmpdistance[0]/$tmpdistance[1]).'mm';
}
## 셔터속도
$exposuretime = '';
if($<span style="background-color:YELLOW; color:RED;">exif</span>['ExposureTime']){
$tmpexpo = explode('/',$<span style="background-color:YELLOW; color:RED;">exif</span>['ExposureTime']);
$exposuretime = ($tmpexpo[0]/$tmpexpo[0]).'/'.($tmpexpo[1]/$tmpexpo[0]).'s';
}
## 초점거리
$focallength = '';
if($<span style="background-color:YELLOW; color:RED;">exif</span>['FocalLength']){
$tmpfocal = explode('/',$<span style="background-color:YELLOW; color:RED;">exif</span>['FocalLength']);
$focallength= ($tmpfocal[0]/$tmpfocal[1]).'mm';
}
#print_r($<span style="background-color:YELLOW; color:RED;">exif</span>);
# 파일 사이즈
$psize = sprintf("%0.1f KB", ($<span style="background-color:YELLOW; color:RED;">exif</span>['FileSize']/1024));
if($psize>1024){
$psize = sprintf("%0.1f MB", ($psize/1024)); //수점 이하가 0.5 는 1로 반올림한다.
}
# ccdsize
$ccdsize = ($<span style="background-color:YELLOW; color:RED;">exif</span>['CCDWidth']) ? substr($<span style="background-color:YELLOW; color:RED;">exif</span>['CCDWidth'],0,5).' mm' : '';
# 사진 크기 (가로x세로)
if(!empty($<span style="background-color:YELLOW; color:RED;">exif</span>['<span style="background-color:YELLOW; color:RED;">Exif</span>ImageWidth'])){
$filewh = $<span style="background-color:YELLOW; color:RED;">exif</span>['<span style="background-color:YELLOW; color:RED;">Exif</span>ImageWidth'].' x '.$<span style="background-color:YELLOW; color:RED;">exif</span>['<span style="background-color:YELLOW; color:RED;">Exif</span>ImageLength'];
}else if(!empty($<span style="background-color:YELLOW; color:RED;">exif</span>['COMPUTED']['Width'])){
$filewh = $<span style="background-color:YELLOW; color:RED;">exif</span>['COMPUTED']['Width'].' x '.$<span style="background-color:YELLOW; color:RED;">exif</span>['COMPUTED']['Height'];
}else{
$size = self::getImageInfo();
$filewh = $size['filewh'];
}

# 기타 정보
$args = array(
'filename' => $<span style="background-color:YELLOW; color:RED;">exif</span>['FileName'], // 파일명
'filesize' => $psize, // 파일사이즈
'datetime' => $<span style="background-color:YELLOW; color:RED;">exif</span>['DateTimeOriginal'], // 촬영일자
'filewh' => $filewh, // 픽셀
'flashonoff' => $flash, // 플래시 사용여부
'mademodel' => $cameramodel, // 제품명
'focallength' => $focallength, // 초점거리
'focusdistance' => $focusdistance, // 촬영거리
'aperture' => $<span style="background-color:YELLOW; color:RED;">exif</span>['COMPUTED']['ApertureFNumber'],// 조리개
'exposuretime' => $exposuretime, // 셔터속도
'isospeed' => $<span style="background-color:YELLOW; color:RED;">exif</span>['ISOSpeedRatings'], // ISO 감도
'<span style="background-color:YELLOW; color:RED;">exif</span>version' => $<span style="background-color:YELLOW; color:RED;">exif</span>['<span style="background-color:YELLOW; color:RED;">Exif</span>Version'], // <span style="background-color:YELLOW; color:RED;">exif</span> 버전
'ccdsize' => $ccdsize, // CCD 크기
'software' => $<span style="background-color:YELLOW; color:RED;">exif</span>['Software'], // 펌웨어 버전
'comments' => $<span style="background-color:YELLOW; color:RED;">exif</span>['Comments'], // 설명
'whitebalance' => $<span style="background-color:YELLOW; color:RED;">exif</span>['WhiteBalance'] // 화이트발란스
);
return $args;
}
# <span style="background-color:YELLOW; color:RED;">exif</span> 정보 또는 이미지 기본 정보
public function get<span style="background-color:YELLOW; color:RED;">Exif</span>(){
if($this-><span style="background-color:YELLOW; color:RED;">exif</span>mode === _READ_<span style="background-color:YELLOW; color:RED;">EXIF</span>_ON_){
return self::set<span style="background-color:YELLOW; color:RED;">Exif</span>();
} else if($this-><span style="background-color:YELLOW; color:RED;">exif</span>mode === _READ_<span style="background-color:YELLOW; color:RED;">EXIF</span>_OFF_){
return self::getImageInfo();
}
}
}
?>



## 테스트하기
필요한거 있음 클래스에 더 추가 하셔서 사용하심 됩니다
<?php
$out->outPrintln("<img src='./testdirectory/P100119003.jpg'>");
$<span style="background-color:YELLOW; color:RED;">exif</span> = new Image<span style="background-color:YELLOW; color:RED;">Exif</span>($path.'/testdirectory/P100119003.jpg');
$args = $<span style="background-color:YELLOW; color:RED;">exif</span>->get<span style="background-color:YELLOW; color:RED;">Exif</span>();
if(is_array($args)){
foreach($args as $k =>$v){
if(!empty($v)){
$out->outPrintln($k.' : '.$v);
}
}
}
$out->outPrintln("----------------------------");
$out->outPrintln("<img src='./testdirectory/DSC_0369.JPG'>");
$<span style="background-color:YELLOW; color:RED;">exif</span>2 = new Image<span style="background-color:YELLOW; color:RED;">Exif</span>($path.'/testdirectory/DSC_0369.JPG');
$args2 = $<span style="background-color:YELLOW; color:RED;">exif</span>2->get<span style="background-color:YELLOW; color:RED;">Exif</span>();
if(is_array($args2)){
foreach($args2 as $k2 =>$v2){
if(!empty($v2)){
$out->outPrintln($k2.' : '.$v2);
}
}
}
?>

댓글목록

등록된 댓글이 없습니다.

PHP
871 (3/18P)

Search

Copyright © Cmd 명령어 3.148.106.49