PDA

View Full Version : How to read aux:Lens from xmp image info?


howardB666
08-13-2007, 06:19 AM
How to read aux:Lens from xmp image info?

My first post, I hope this thread is where it should be.

I’m trying to read lens name info from a JPG image saved from PS.

From what I can conjure up with google I’ve narrowed it down to this PHP function by Pekka Saarinen

http://photography-on-the.net/ee/beta/cs_xmp_to_exif.php

<?php

$xmp_parsed = ee_extract_exif_from_pscs_xmp ("CRW_0016b_preview.jpg",1);

function ee_extract_exif_from_pscs_xmp ($filename,$printout=0) {

// very straightforward one-purpose utility function which
// reads image data and gets some EXIF data (what I needed) out from its XMP tags (by Adobe Photoshop CS)
// returns an array with values
// code by Pekka Saarinen http://photography-on-the.net

ob_start();
readfile($filename);
$source = ob_get_contents();
ob_end_clean();

$xmpdata_start = strpos($source,"<x:xmpmeta");
$xmpdata_end = strpos($source,"</x:xmpmeta>");
$xmplenght = $xmpdata_end-$xmpdata_start;
$xmpdata = substr($source,$xmpdata_start,$xmplenght+12);

$xmp_parsed = array();

$regexps = array(
array("name" => "DC creator", "regexp" => "/<dc:creator>\s*<rdf:Seq>\s*<rdf:li>.+<\/rdf:li>\s*<\/rdf:Seq>\s*<\/dc:creator>/"),
array("name" => "TIFF camera model", "regexp" => "/<tiff:Model>.+<\/tiff:Model>/"),
array("name" => "TIFF maker", "regexp" => "/<tiff:Make>.+<\/tiff:Make>/"),
array("name" => "EXIF exposure time", "regexp" => "/<exif:ExposureTime>.+<\/exif:ExposureTime>/"),
array("name" => "EXIF f number", "regexp" => "/<exif:FNumber>.+<\/exif:FNumber>/"),
array("name" => "EXIF aperture value", "regexp" => "/<exif:ApertureValue>.+<\/exif:ApertureValue>/"),
array("name" => "EXIF exposure program", "regexp" => "/<exif:ExposureProgram>.+<\/exif:ExposureProgram>/"),
array("name" => "EXIF iso speed ratings", "regexp" => "/<exif:ISOSpeedRatings>\s*<rdf:Seq>\s*<rdf:li>.+<\/rdf:li>\s*<\/rdf:Seq>\s*<\/exif:ISOSpeedRatings>/"),
array("name" => "EXIF datetime original", "regexp" => "/<exif:DateTimeOriginal>.+<\/exif:DateTimeOriginal>/"),
array("name" => "EXIF exposure bias value", "regexp" => "/<exif:ExposureBiasValue>.+<\/exif:ExposureBiasValue>/"),
array("name" => "EXIF metering mode", "regexp" => "/<exif:MeteringMode>.+<\/exif:MeteringMode>/"),
array("name" => "EXIF focal lenght", "regexp" => "/<exif:FocalLength>.+<\/exif:FocalLength>/"),
array("name" => "AUX lens", "regexp" => "/<aux:Lens>.+<\/aux:Lens>/")
);

foreach ($regexps as $key => $k) {
$name = $k["name"];
$regexp = $k["regexp"];
unset($r);
preg_match ($regexp, $xmpdata, $r);
$xmp_item = "";
$xmp_item = @$r[0];
array_push($xmp_parsed,array("item" => $name, "value" => $xmp_item));
}

if ($printout == 1) {
foreach ($xmp_parsed as $key => $k) {
$item = $k["item"];
$value = $k["value"];
print "<br><b>" . $item . ":</b> " . $value;
}
}

return ($xmp_parsed);

}

?>

I’m only interested in returning the info from the last index in the array “AUX lens” where is will tell you the name of the lens used in the image ex. “EF24-70mm f/2.8L USM”

I’ve been trying to get this custom function to work in pixelpost with modding the functions _exif.php file but my lack of PHP knowledge and a decent way to debugging has stumped me, I know this method will work but someone with a handle on PHP is needed

i can be emailed at bryan AT bryan-howard DOT com

Dennis
08-13-2007, 06:44 AM
well first off you should not try to hack the core functions of Pixelpost. Secondly this should be done in an addon.
Third, I'll whip something up for you asap.

howardB666
08-16-2007, 03:20 AM
Ok im trying to get this to work as an addon but, I’m stuck with this code

array("name" => "AUX lens", "regexp" => "/<aux:Lens>.+<\/aux:Lens>/")

this bit of code won’t work because “aux…” isn’t in tags. Its in the form as

aux:Lens="EF24-70mm f/2.8L USM" aux:ImageNumber….

I then tried this bit of code for the search

array("name" => "AUX lens", "regexp" => "/aux:Lens=\".+aux:ImageNumber=\"64\"/")

but then got

aux:Lens="EF24-70mm f/2.8L USM" aux:ImageNumber="64"

so my question is how to ignore all the aux stuff and only return EF24-70mm f/2.8L USM

Dkozikowski
08-16-2007, 10:18 AM
I'm not too familiar with the EXIF functions as I have never taken the plunge into those files but a regex like this:


aux:Lens="(.*?)"


would pull out

EF24-70mm f/2.8L USM

from this string,

aux:Lens="EF24-70mm f/2.8L USM" aux:ImageNumber="64"

Dennis
08-16-2007, 12:06 PM
I'm working on an addon as we speak.

howardB666
08-16-2007, 09:46 PM
Dennis your addon will no doubt be far superior to mine and i will pick it apart when i get stuck again :)

Dennis
08-17-2007, 07:24 AM
Howard, I seriously doubt that my addon will be far more superior, after all it is based on the same code. ;)

Dennis
08-17-2007, 12:35 PM
It's going to take a little bit more to get this all working. I can extract the info you want, but I don't want to stop there.

HavePh8
10-05-2007, 06:53 PM
hi there,
just wondering if there has been an progress with this addon.
Thank you.

Dennis
10-07-2007, 01:48 PM
Yes, there is. However, I use some code which is not freely available at this point. I'm still waiting if I can release it.

Detonate
12-20-2007, 07:33 PM
Heya! Any update on this?

I've been scowering the Internet trying to figure out how to pulls Lens data for my Nikon DSLR.

Came across many posts about EXIF, MakerNotes, etc, etc... And finally I decided to download a complete EXIF reader to find out exactly where and what data is stored.

What I found is that info that is stored in the "Maker" section on unedited pictures, is moved to the XMP section on photo's edited in Photoshop. Which all of mine are.

I'm desperately trying to extract the "Lens" information. But heck, I wouldn't mind being able to grab some of the other info in there as well.

Ulitmately I want to take this Lens info and have a Small Icon of the lens used with a link to Nikon's site for that lens.

Dennis
12-21-2007, 06:26 AM
Yes, there is. However, I use some code which is not freely available at this point. I'm still waiting if I can release it.

I still haven't heard from him if I can use the code. I probably clean it up this week and get it to work somehow.

Detonate
12-21-2007, 12:37 PM
Cool! Keep me in the loop.

I have a few other ideas that would be based off of this concept. If you are interested in earning a commision, contact me offline and I'll tell you what I'm looking for.

tomms
05-13-2008, 10:03 PM
any progress on this?

cheers

Dennis
05-14-2008, 05:10 AM
I have something ready yes, but I'm swamped at the moment.

tomms
05-14-2008, 07:09 PM
thanks for the reply dennis ill be waiting eagerly