Killersites.com Homepage Welcome Guest   |   Register  |  Login
Login Name Password
  Search  
  Index  | Recent Threads  | Unanswered Threads  | Who's Online  | User List  | Help


Quick Go »

No member browsing this thread
Thread Status: Active
Total posts in this thread: 5
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 4191 times and has 4 replies Next Thread
Male swurp
Member
Member's Avatar

USA
Joined: Mar 11, 2008
Post Count: 95
Status: Offline
Reply to this Post  Reply with Quote 
Using PHP to extract Exif Data From Pictures

I want to extract the Exif Data (date, time, f-stop, ISO, shudderspeed) from images using a PHP script.
Here is the site, just choose any of the links on the left and you will see a picture(s) and their exif data to the right of the picture.

http://birds.adamvalencic.com

But the exif data is currently hardcoded, meaning yes, I entered it like 53 times, literally. I found some help on php.net and got this far:

http://birds.adamvalencic.com/test.php

that test page uses this code:

<img src="images/wren.jpg" alt="wrens" />
<?php
$exif = exif_read_data('images/wren.jpg', 0, true);
echo "test2.jpg:<br />\n";
foreach ($exif as $key => $section) {
foreach ($section as $name => $val) {
echo "$key.$name: $val<br />\n";
}
}
?>


That is a good start, but I don't want all of that, I just want certain parts of it. I read on php.net that the data is all stored in an array, but I can't figure out what it's called. Plus, once I get the code to only display the exif data I want, I need to get rid of the Exif description and just get the value itself . For example,
EXIF.FocalLength: 3000/10
get rid of EXIF.FocalLength: and just display 3000/10.

I know, this is a tall order...
----------------------------------------
Running IE6, IE7, and FF2

[Jun 11, 2008 9:05:55 AM] Show Printable Version of Post    View Member Profile    Send Private Message    Hidden to Guest [Link] Report threatening or abusive post: please login first  Go to top 
Male admin
Advanced Member
Member's Avatar


Joined: Jun 14, 2003
Post Count: 2940
Status: Offline
Reply to this Post  Reply with Quote 
Re: Using PHP to extract Exif Data From Pictures

Hi,

All you need to do is get the key names and then only display the ones you want.

If you don't know the key names, then use the index position:

echo $array[0];

echo $array[1];

... and so on.

In you case the array is contained in $exif.


Stefan
----------------------------------------
Stefan Mischook

Video Tutorial Store | Web Templates
[Jun 11, 2008 9:47:48 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male swurp
Member
Member's Avatar

USA
Joined: Mar 11, 2008
Post Count: 95
Status: Offline
Reply to this Post  Reply with Quote 
Re: Using PHP to extract Exif Data From Pictures

Thanks! But that only solves half of my problem. Take this code for example:

<img src="images/wren.jpg" alt="wrens" />
<?php
$exif = exif_read_data('images/wren.jpg', 0, true);
echo "test2.jpg:<br />\n";
foreach ($exif as $key => $section) {
foreach ($section as $name => $val) {
if($name == 'DateTimeOriginal'){
echo "$val";
}

}
}
?>


This outputs the Date and Time from the Exif in this format:

2007:05:11 09:03:06

I need to change that into something like this:
05/11/2007 09:03am

I know it is fairly simple, but I just don't know all the syntax for php.

And even more importantly, I get a bunch of outputs like this:

3000/10 which needs to be 300

and 56/10 which needs to be 5.6

is there a way to do the math in PHP?
----------------------------------------
Running IE6, IE7, and FF2
----------------------------------------
[Edit 1 times, last edit by swurp at Jun 11, 2008 9:59:07 AM]
[Jun 11, 2008 9:56:54 AM] Show Printable Version of Post    View Member Profile    Send Private Message    Hidden to Guest [Link] Report threatening or abusive post: please login first  Go to top 
Male swurp
Member
Member's Avatar

USA
Joined: Mar 11, 2008
Post Count: 95
Status: Offline
Reply to this Post  Reply with Quote 
Re: Using PHP to extract Exif Data From Pictures

I figured this one out. I opted not to use the date/time stuff because they weren't set correctly anyways. But here is how I got the rest of the data:

<?php
function ex($param){
$exif = exif_read_data($param, 0, true);
foreach ($exif as $key => $section) {
foreach ($section as $name => $val) {
if($name == 'ExposureTime'){
echo "<h2>Exposure Time:</h2>";
echo "<h3> $val sec</h3>";
}
if($name == 'FNumber'){
list($pt1, $pt2) = split('[/.-]', $val);
$fstop=$pt1/$pt2;
echo "<h2>F-Stop:</h2>";
echo "<h3>$fstop</h3>";
}
if($name =='ISOSpeedRatings'){
echo "<h2>ISO:</h2>";
echo "<h3> $val</h3>";
}
if($name =='FocalLength'){
list($pt1, $pt2) = split('[/.-]', $val);
$focal=$pt1/$pt2;
echo "<h2>Focal Length:</h2>";
echo "<h3> $focal</h3>";
}
if($name =='Make'){
echo "<h1>Camera:</h1>";
echo "<p>$val</p>";
}

}
}
}
?>
----------------------------------------
Running IE6, IE7, and FF2
[Jun 11, 2008 1:56:55 PM] Show Printable Version of Post    View Member Profile    Send Private Message    Hidden to Guest [Link] Report threatening or abusive post: please login first  Go to top 
Male unclepips
Stranger




Joined: Jun 13, 2008
Post Count: 1
Status: Offline
Reply to this Post  Reply with Quote 
smile Re: Using PHP to extract Exif Data From Pictures

Hi Swurp,

I've just spent all day on this exact topic, and at the moment am searching on how to ADD EXIF data to my exisiting JPG's.

Anyway, below is all the code I used to get the information that I wanted from my photos. Hope this is of use to you.....

$pathfile is the path and filename of the photograph you want the information from.



$exif = read_exif_data($pathfile, 0, true);
$filename = strtolower($exif['FILE']['FileName']);
$filedatename = $exif['FILE']['FileDateTime'];
$filesize = $exif['FILE']['FileSize'];
$filetype = $exif['FILE']['FileType'];
$mimetype = $exif['FILE']['MimeType'];
$height = $exif['COMPUTED']['Height'];
$width = $exif['COMPUTED']['Width'];
$iscolor = $exif['COMPUTED']['IsColor'];
$fstop = $exif['COMPUTED']['ApertureFNumber'];
$imagewidth = $exif['IFD0']['ImageWidth'];
$imagelength = $exif['IFD0']['ImageLength'];
$compression = $exif['IFD0']['Compression'];
$make = $exif['IFD0']['Make'];
$model = str_replace($make,'',$exif['IFD0']['Model']);
$orientation = $exif['IFD0']['Orientation'];
$xresolution = $exif['IFD0']['XResolution'];
$yresolution = $exif['IFD0']['YResolution'];
$resolutionunit = $exif['IFD0']['ResolutionUnit'];
$datetime = $exif['IFD0']['DateTime'];
$exposure = $exif['EXIF']['ExposureTime'].' sec';
$fnumber = $exif['EXIF']['FNumber'];
$exposureprogram = $exif['EXIF']['ExposureProgram'];
$iso = $exif['EXIF']['ISOSpeedRatings'];
$exifversion = $exif['EXIF']['ExifVersion'];
$datetimeoriginal = $exif['EXIF']['DateTimeOriginal'];
$exposurebias = $exif['EXIF']['ExposureBiasValue'];
$meteringmode = $exif['EXIF']['MeteringMode'];
$flash = $exif['EXIF']['Flash'];
$exifimagewidth = $exif['EXIF']['ExifImageWidth'];
$exifimagelength = $exif['EXIF']['ExifImageLength'];
$exposuremode = $exif['EXIF']['ExposureMode'];
$whitebalance = $exif['EXIF']['WhiteBalance'];
$imagetype = $exif['MAKERNOTE']['ImageType'];
$ownername = $exif['MAKERNOTE']['OwnerName'];
$cameraserial = $exif['MAKERNOTE']['Camera'];
$lens = $exif['MAKERNOTE']['UndefinedTag:0x0095'];
$focallength = intval($exif['EXIF']['FocalLength']).' mm';
$copyright = $exif['COMPUTED']['Copyright'];
$yy = substr($datetimeo,0,4);
$mm = substr($datetimeo,5,2);
$dd = substr($datetimeo,8,2);
$h = substr($datetimeo,11,2);
$m = substr($datetimeo,14,2);
$s = substr($datetimeo,17,2);
$tt = "am";
if($h>=13) {$h=$h-12; $tt="pm"; }
$date = $dd.'/'.$mm.'/'.$yy;
$time = $h.':'.$m.':'.$s.' '.$tt;


Cheers,
Phil.
[Jun 13, 2008 1:44:37 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
[ Jump to Last Post ]
Show Printable Version of Thread  Post new Thread