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
https://forums.phpfreaks.com/topic/33955-exif-arrays/
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
https://forums.phpfreaks.com/topic/33955-exif-arrays/#findComment-159478
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.