Olympus UK E-System User Group
Olympus UK E-System User Group

Join our unique resource for Olympus Four Thirds E-System DSLR and Pen and OM-D Micro Four Thirds photographers. Show your images via our free e-group photo gallery. Please read the e-group.uk.net forum terms and conditions before posting for the first time. Above all, welcome!


Go Back   Olympus UK E-System User Group > Out of Focus area > The lounge

The lounge Relax, take a break from photo and camera talk - have a chat about something else for a change. Just keep it clean and polite!

Reply
 
Thread Tools Display Modes
  #1  
Old 3rd July 2011
Ian's Avatar
Ian Ian is offline
Administrator
 
Join Date: Jul 2007
Location: Hemel Hempstead, Hertfordshire, UK
Posts: 11,652
Thanks: 427
Thanked 2,545 Times in 1,279 Posts
Likes: 882
Liked 1,755 Times in 791 Posts
Any php specialists out there?

On DPNow and Four Thirds User we use an in-house developed script that extracts exif data for our articles that show sample images, for example:

http://fourthirds-user.com/2010/09/m...ge_samples.php

But in the two latest articles where we have run this script the exif data has been largely nonsense (only the ISO data is captured correcly), see:

http://dpnow.com/8068b.html

These two articles feature samples from two very new cameras, the Panasonic Lumix DMC-GF3 and the Olympus Pen E-P3. It suggests that there is a change to the EXIF data format that our script can't cope with.

My understanding us that our script calls a PHP5 EXIF extension. The server host admin have updated PHP5 to the latest version but this has not fixed the problem.

On the users' photo galleries the problem is not there, probably because we use JHEAD for exif there.

So before we rewrite our script to use something like JHEAD instead of PHP EXIF - does anybody have some suggestions to make?

Thanks!

Ian
__________________
Founder and editor of:
Olympus UK E-System User Group (http://e-group.uk.net)
Four Thirds User (http://fourthirds-user.com)
Digital Photography Now (http://dpnow.com)
Olympus camera, lens, and accessory hire (http://e-group.uk.net/hire)

Twitter: www.twitter.com/ian_burley
Flickr: www.flickr.com/photos/dpnow/
Pinterest: www.pinterest.com/ianburley/
NEW: My personal BLOG ianburley.com
Reply With Quote
  #2  
Old 6th July 2011
mas
Guest
 
Posts: n/a
Re: Any php specialists out there?

Can you show your code and/or identify whatever extension you invoke?
Reply With Quote
  #3  
Old 6th July 2011
timg timg is offline
Full member
 
Join Date: Aug 2008
Location: Cornwall, UK
Posts: 1,208
Thanks: 43
Thanked 115 Times in 110 Posts
Likes: 13
Liked 73 Times in 38 Posts
Re: Any php specialists out there?

I've worked in PHP in the past although not used the EXIF function.

Looking at the dpnow page it looks like you're extracting the EXIF information from JPGs, if so are you taking the images straight from the camera or are you using different software to convert from RAW?

Even though they're new cameras, you would expect them to follow standard JPG encoding.
__________________
GX7, EP3, 9-18, 14-45, 45-150, 20 1.7, 25 1.4, 45 1.8, FL36 & various OM glass. flickr
Reply With Quote
  #4  
Old 6th July 2011
Kees's Avatar
Kees Kees is offline
Full member
 
Join Date: Jul 2010
Location: Netherlands
Posts: 202
Thanks: 39
Thanked 18 Times in 15 Posts
Likes: 0
Liked 0 Times in 0 Posts
Re: Any php specialists out there?

I'm using the Google Chrome EXIF Reader utility and it works just fine and gives the correct EXIF information from these pictures. Seems like the actual EXIF info layout in these pictures is still the same.
Reply With Quote
  #5  
Old 6th July 2011
Ian's Avatar
Ian Ian is offline
Administrator
 
Join Date: Jul 2007
Location: Hemel Hempstead, Hertfordshire, UK
Posts: 11,652
Thanks: 427
Thanked 2,545 Times in 1,279 Posts
Likes: 882
Liked 1,755 Times in 791 Posts
Re: Any php specialists out there?

My technical guru, David, wrote the script. There are errors that appear when viewing the exif of thes latest cameras that are not present when reading exif from earlier cameras.

The script extracts the exif data from the camera JPEG, which is not edited.

I have asked David if he can look in on the thread here.

Ian
__________________
Founder and editor of:
Olympus UK E-System User Group (http://e-group.uk.net)
Four Thirds User (http://fourthirds-user.com)
Digital Photography Now (http://dpnow.com)
Olympus camera, lens, and accessory hire (http://e-group.uk.net/hire)

Twitter: www.twitter.com/ian_burley
Flickr: www.flickr.com/photos/dpnow/
Pinterest: www.pinterest.com/ianburley/
NEW: My personal BLOG ianburley.com
Reply With Quote
  #6  
Old 7th July 2011
Ian's Avatar
Ian Ian is offline
Administrator
 
Join Date: Jul 2007
Location: Hemel Hempstead, Hertfordshire, UK
Posts: 11,652
Thanks: 427
Thanked 2,545 Times in 1,279 Posts
Likes: 882
Liked 1,755 Times in 791 Posts
Re: Any php specialists out there?

David has provided me with this:

Code:
 // extract and display the exif data
       $exif = exif_read_data($myfile);
       if (strpos($exif['ExposureTime'],"/"))
           {
           $tmpexposuretime=explode("/",$exif['ExposureTime']);
           if ($tmpexposuretime[0] > 1)
               {
               $tmpexposuretime[1]=round($tmpexposuretime[1]/$tmpexposuretime[0]);
               }
           $exposuretime="1/$tmpexposuretime[1]"; 
           }
       else
           {
           $exposuretime=$exif['ExposureTime'];
           }
       $tmpaperture=explode("/",$exif['FNumber']);
       $aperture=$tmpaperture[0]/$tmpaperture[1];
       $aperture=sprintf("%01.1f", $aperture);
       $ISO=$exif['ISOSpeedRatings'];
       $tmpfocallength=explode("/",$exif['FocalLength']);
       if ($tmpfocallength[1] > 0)
           {
           $newfocallength=$tmpfocallength[0]/$tmpfocallength[1];
           $focallength=round_to($newfocallength, 0.5);
           }
       else
           {
           $focallength=" - ";
           }
       echo "Shutter Speed: $exposuretime sec.<br />\n";
       echo "Aperture: f/$aperture<br />\n";
       if (is_array($ISO)) {echo "ISO: $ISO[0]<br />\n";} else {echo "ISO: $ISO<br />\n";}
       echo "Focal Length: $focallength<sup></sup>mm<br />\n";
Hope this makes sense!

Ian
__________________
Founder and editor of:
Olympus UK E-System User Group (http://e-group.uk.net)
Four Thirds User (http://fourthirds-user.com)
Digital Photography Now (http://dpnow.com)
Olympus camera, lens, and accessory hire (http://e-group.uk.net/hire)

Twitter: www.twitter.com/ian_burley
Flickr: www.flickr.com/photos/dpnow/
Pinterest: www.pinterest.com/ianburley/
NEW: My personal BLOG ianburley.com
Reply With Quote
  #7  
Old 8th July 2011
mas
Guest
 
Posts: n/a
Re: Any php specialists out there?

That should let us sort it out.

I'll have a look this evening.
Reply With Quote
The Following User Says Thank You to For This Useful Post:
Ian (8th July 2011)
  #8  
Old 8th July 2011
timg timg is offline
Full member
 
Join Date: Aug 2008
Location: Cornwall, UK
Posts: 1,208
Thanks: 43
Thanked 115 Times in 110 Posts
Likes: 13
Liked 73 Times in 38 Posts
Re: Any php specialists out there?

Just had a quick look and it looks as though the problem lies within the exif_read_data function, not what David has done...

From an E5 file this returns:

[ExposureTime] => 1/3200
[FNumber] => 56/10
[ISOSpeedRatings] => 400
[FocalLength] => 60/1


From the EP3 file this returns:

[ExposureTime] => 1/0
[FNumber] => 0/10
[ISOSpeedRatings] => 160
[FocalLength] => 100/677


Which doesn't seem to make a lot of sense... looks like you may have to update to the JHEAD function.
__________________
GX7, EP3, 9-18, 14-45, 45-150, 20 1.7, 25 1.4, 45 1.8, FL36 & various OM glass. flickr
Reply With Quote
  #9  
Old 8th July 2011
timg timg is offline
Full member
 
Join Date: Aug 2008
Location: Cornwall, UK
Posts: 1,208
Thanks: 43
Thanked 115 Times in 110 Posts
Likes: 13
Liked 73 Times in 38 Posts
Re: Any php specialists out there?

Just-in-case anyone else wants to have a look this should save a bit of time:

<html>
<body>
<?php

function exif($myfile)
{
// extract and display the exif data
$exif = exif_read_data($myfile);

echo "<pre>";
//print_r($exif['ExposureTime']);
print_r($exif);
echo "</pre>";


if (strpos($exif['ExposureTime'],"/"))
{
$tmpexposuretime=explode("/",$exif['ExposureTime']);
if ($tmpexposuretime[0] > 1)
{
$tmpexposuretime[1]=round($tmpexposuretime[1]/$tmpexposuretime[0]);
}
$exposuretime="1/$tmpexposuretime[1]";
}
else
{
$exposuretime=$exif['ExposureTime'];
}
$tmpaperture=explode("/",$exif['FNumber']);
$aperture=$tmpaperture[0]/$tmpaperture[1];
$aperture=sprintf("%01.1f", $aperture);
$ISO=$exif['ISOSpeedRatings'];
$tmpfocallength=explode("/",$exif['FocalLength']);
if ($tmpfocallength[1] > 0)
{
$newfocallength=$tmpfocallength[0]/$tmpfocallength[1];
//$focallength=round_to($newfocallength, 0.5);
$focallength=round($newfocallength);
}
else
{
$focallength=" - ";
}
echo "Shutter Speed: $exposuretime sec.<br />\n";
echo "Aperture: f/$aperture<br />\n";
if (is_array($ISO)) {echo "ISO: $ISO[0]<br />\n";} else {echo "ISO: $ISO<br />\n";}
echo "Focal Length: $focallength<sup></sup>mm<br />\n";
}

print "start<br>";
exif("/home/.../good.jpg");
print "---<br>";
exif("/home/.../bad.jpg");
print "end<br>";

?>
</body>
</html>
__________________
GX7, EP3, 9-18, 14-45, 45-150, 20 1.7, 25 1.4, 45 1.8, FL36 & various OM glass. flickr
Reply With Quote
  #10  
Old 9th July 2011
Ian's Avatar
Ian Ian is offline
Administrator
 
Join Date: Jul 2007
Location: Hemel Hempstead, Hertfordshire, UK
Posts: 11,652
Thanks: 427
Thanked 2,545 Times in 1,279 Posts
Likes: 882
Liked 1,755 Times in 791 Posts
Re: Any php specialists out there?

Has anyone noticed anything if interest from the code?

Ian
__________________
Founder and editor of:
Olympus UK E-System User Group (http://e-group.uk.net)
Four Thirds User (http://fourthirds-user.com)
Digital Photography Now (http://dpnow.com)
Olympus camera, lens, and accessory hire (http://e-group.uk.net/hire)

Twitter: www.twitter.com/ian_burley
Flickr: www.flickr.com/photos/dpnow/
Pinterest: www.pinterest.com/ianburley/
NEW: My personal BLOG ianburley.com
Reply With Quote
  #11  
Old 9th July 2011
Kees's Avatar
Kees Kees is offline
Full member
 
Join Date: Jul 2010
Location: Netherlands
Posts: 202
Thanks: 39
Thanked 18 Times in 15 Posts
Likes: 0
Liked 0 Times in 0 Posts
Re: Any php specialists out there?

I'm pretty sure either the exif_read_data function is corrupt or picking up the wrong input ($myfile). I don't think the error is in this code.
I'm not an expert on PHP, and my programming experience is from long ago, but I'd write a test script to sort this out. The scrip would just display the contents of the result of exif_read_data($myfile).
Reply With Quote
  #12  
Old 10th July 2011
PaulE PaulE is offline
Full member
 
Join Date: May 2008
Location: Mid Wales
Posts: 330
Thanks: 0
Thanked 3 Times in 3 Posts
Likes: 0
Liked 0 Times in 0 Posts
Re: Any php specialists out there?

The problem is that the Panasonic Lumix DMC-GF3 and the Olympus Pen E-P3 appear to abandon the use of the EXIF.ExposureTime and EXIF.FNumber etc and now appear to record the details under new tags EXIF.ShutterSpeedValue and EXIF.ApertureValue instead - It's not a fault with the php exif_read_data funtion or neccessarily the script you've had made either. The odd thing is the old tags are still present within the DMC-GF3 exif but they are filled with incorrect values - which is what your script is correctly returning.

A simple print_r of the array returned by exif_read_data for an E5 file and one from the DMC-GF3 and you can clearly see the differences and why the script is returning bad data - as you predicted - there is a change to the EXIF data format that your script can't cope with.

If I get a bit more free time this afternoon I'll have another play with it - getting it to work with the new Exif shouldn't be too hard (in theory anyway) I'll see what I can do...
Reply With Quote
  #13  
Old 10th July 2011
PaulE PaulE is offline
Full member
 
Join Date: May 2008
Location: Mid Wales
Posts: 330
Thanks: 0
Thanked 3 Times in 3 Posts
Likes: 0
Liked 0 Times in 0 Posts
Re: Any php specialists out there?

OK, I did a little bit of reading and it seems the difference in the exif tags is due to the newer cameras using exif version 0230 rather than 0221. With the help of the php exif manual specifically some helpful guys functions I altered your script a little in an attempt to cater for the different exif versions. It seems to work with the very limited sample of photos I tried. For some very strange reason the focal length for the samples I used (from your link above) record a shutter speed of 100/677mm or 0.15mm when rounded - obviously a factor of 10 out so this part will need a little more thought - especially when it seems like it will only likely crop up with certain shutter speeds?

Code:
// extract and display the exif data
	$exif = exif_read_data($myfile);
       
	
	// CHECK EXIF VERSION
		if ($exif['ExifVersion'] > "0221"){
	   
			$exposuretime = exif_get_shutter($exif);
			$aperture = exif_get_fstop($exif);
		}
	   
		Else { 
			
			if (strpos($exif['ExposureTime'],"/"))
			   {
			   $tmpexposuretime=explode("/",$exif['ExposureTime']);
			   if ($tmpexposuretime[0] > 1)
				   {
				   $tmpexposuretime[1]=round($tmpexposuretime[1]/$tmpexposuretime[0]);
				   }
			   $exposuretime="1/$tmpexposuretime[1]"; 
			   }
		   else
			   {
			   $exposuretime=$exif['ExposureTime'];
			   } 


		   $tmpaperture=explode("/",$exif['FNumber']);
		   $aperture=$tmpaperture[0]/$tmpaperture[1];
		   $aperture=sprintf("%01.1f", $aperture);
	   
	
		}
	//

	
	$tmpfocallength=explode("/",$exif['FocalLength']);
	if ($tmpfocallength[1] > 0){
		$newfocallength=$tmpfocallength[0]/$tmpfocallength[1];
		$focallength=round($newfocallength, 2);
	}
	
	else{
		$focallength=" - ";
	}


	$ISO=$exif['ISOSpeedRatings'];
	
	echo "Shutter Speed: $exposuretime sec.<br />\n";
	echo "Aperture: f/$aperture<br />\n";
	if (is_array($ISO)) {echo "ISO: $ISO[0]<br />\n";} else {echo "ISO: $ISO<br />\n";}
	echo "Focal Length: $focallength<sup></sup>mm<br />\n";


	///// FUNCTIONS  

		function exif_get_float($value) {
			$pos = strpos($value, '/');
			if ($pos === false) return (float) $value;
			$a = (float) substr($value, 0, $pos);
			$b = (float) substr($value, $pos+1);
			return ($b == 0) ? ($a) : ($a / $b);
		}

		function exif_get_shutter(&$exif) {
			if (!isset($exif['ShutterSpeedValue'])) return false;
			$apex    = exif_get_float($exif['ShutterSpeedValue']);
			$shutter = pow(2, -$apex);
			if ($shutter == 0) return false;
			if ($shutter >= 1) return round($shutter) . 's';
			return '1/' . round(1 / $shutter) . 's';
		}

		function exif_get_fstop(&$exif) {
			if (!isset($exif['ApertureValue'])) return false;
			$apex  = exif_get_float($exif['ApertureValue']);
			$fstop = pow(2, $apex/2);
			if ($fstop == 0) return false;
			return round($fstop,1);
		}
	//
Hope that gets you a little bit closer to a permanent fix...
Paul.
Reply With Quote
  #14  
Old 10th July 2011
Kees's Avatar
Kees Kees is offline
Full member
 
Join Date: Jul 2010
Location: Netherlands
Posts: 202
Thanks: 39
Thanked 18 Times in 15 Posts
Likes: 0
Liked 0 Times in 0 Posts
Re: Any php specialists out there?

Quote:
Originally Posted by PaulE View Post
The problem is that the Panasonic Lumix DMC-GF3 and the Olympus Pen E-P3 appear to abandon the use of the EXIF.ExposureTime and EXIF.FNumber etc and now appear to record the details under new tags EXIF.ShutterSpeedValue and EXIF.ApertureValue instead - It's not a fault with the php exif_read_data funtion or neccessarily the script you've had made either. The odd thing is the old tags are still present within the DMC-GF3 exif but they are filled with incorrect values - which is what your script is correctly returning.

A simple print_r of the array returned by exif_read_data for an E5 file and one from the DMC-GF3 and you can clearly see the differences and why the script is returning bad data - as you predicted - there is a change to the EXIF data format that your script can't cope with.

If I get a bit more free time this afternoon I'll have another play with it - getting it to work with the new Exif shouldn't be too hard (in theory anyway) I'll see what I can do...
How can it be that my EXIF Reader gives correct results if this is the case?
Reply With Quote
  #15  
Old 10th July 2011
PaulE PaulE is offline
Full member
 
Join Date: May 2008
Location: Mid Wales
Posts: 330
Thanks: 0
Thanked 3 Times in 3 Posts
Likes: 0
Liked 0 Times in 0 Posts
Re: Any php specialists out there?

Quote:
Originally Posted by Kees View Post
How can it be that my EXIF Reader gives correct results if this is the case?
In short I don't quite know - all the 3rd party exif readers I tested return the correct focal length - which it must somehow be calculating from the value 100/677 that is stored in the focal length tag. I'm no mathematician and I gave up trying to work out a solution that would work with a range of shutter speeds.

The other possibilty (although I think is probably unlikely) is that other programs could be using the value for focal length in terms of 35mm film - which is correctly reported as 28mm from other values within the exif ([ResolutionUnit], [YResolution], [YResolution] etc)the crop factor of the sensor can be determined and so an accurate focal length calculated this way - a long way around the problem - which apparently can be unreliable with some cameras as they don't report the resolution data correctly. Of course if Ian only ever planned to use the script with 4/3rds images then he could bodge it by hardcoding the crop factor at 2 and then an accurate FL could be easily caluculated - not a clever idea really though and one that would come back to bite in the future.

Its definitely possible to get it working it's just a matter of time and effort - probably a very easy task for someone who knows what their doing...
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:51 PM.


The Write Technology Ltd, 2007-2019, All rights reservedAd Management plugin by RedTyger