Jump to content

EXIF & Arrays


complex05

Recommended Posts

Hello,

I've built a script but am getting a little confused when it comes to all these arrays.

What my code is doing right now is reading images in a directory and grabbing their EXIF data (GPS specifically)

[code]
<?php

if ($handle = opendir('/home/dtech/public_html/whereisit/maps/'))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
//echo $file;
$image = exif_read_data("maps/$file",0,true);
foreach($image as $key => $section)
{
foreach($section as $name => $value)
{
if(is_array($value))
{
foreach($value as $axis => $coordinate)
{
$coordinate = str_replace("/1","",$coordinate);
$latitude = array();
if($name == "GPSLatitude")
{
echo "<li>" . $coordinate;
}

$longitude = array();
if($name == "GPSLongitude")
{
echo "<li>" . $coordinate;
}
}
}
}
}
}
}

  closedir($handle);
}

print_r($longitude);
print_r($latitude);

?>
[/code]

Each image has GPSLatitude and GPSLongitude, both are arrays. Each array contains 3 values; they look like this

GPSLongitude[0]: 1
GPSLongitude[1]: 2
GPSLongitude[2]: 3

GPSLatitude[0]: 4
GPSLatitude[1]: 5
GPSLatitude[2]: 6

So each image has 6 gps coordinates in total. I am able, so far, to get all the coordinates, but I cannot group them properly into an array. Basically I want it like this:

$image["image1"]["longitude"][0] = 1;
$image["image1"]["longitude"][1] = 2;
$image["image1"]["longitude"][2] = 3;

$image["image1"]["latitude"][0] = 4;
$image["image1"]["latitude"][1] = 5;
$image["image1"]["latitude"][2] = 6;

Any suggestions? I am sort of drawing a blank here.

Thanks
Link to comment
Share on other sites

well noone replied and i figured it out... if anyone was curious here was my solution:

[code]
if ($handle = opendir('/home/dtech/public_html/whereisit/maps/'))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
//echo $file;
$image = exif_read_data("maps/$file",0,true);
$images = array();
$images[$file]["lat"][0] = str_replace("/1","",$image['GPS']['GPSLatitude'][0]);
$images[$file]["lat"][1] = str_replace("/1","",$image['GPS']['GPSLatitude'][1]);
$images[$file]["lat"][2] = str_replace("/1","",$image['GPS']['GPSLatitude'][2]);

$images[$file]["log"][0] = str_replace("/1","",$image['GPS']['GPSLongitude'][0]);
$images[$file]["log"][1] = str_replace("/1","",$image['GPS']['GPSLongitude'][1]);
$images[$file]["log"][2] = str_replace("/1","",$image['GPS']['GPSLongitude'][2]);

print_r($images);
}
}
}
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.