LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-28-2016, 02:22 PM   #1
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Rep: Reputation: 12
Read GPS data from Exif


I am trying to read the GPS data from an image with the following php script.

Code:
<?php

$filename="IMG_0743.JPG";

//  ================== Example of Exif read of GPS Data ==================

$exif = exif_read_data($filename, 'EXIF');

print_r($exif); exit();  <=== To display result

$latitude = gps($exif["GPS.GPSLatitude"], $exif['GPS.GPSLatitudeRef']);
$longitude = gps($exif["GPS"]["GPSLongitude"], $exif["GPS"]['GPSLongitudeRef']);

echo "\nLatitude ".$latitude."\n"; 
echo "Longitude ".$longitude."\n";

echo "\n ======================================== \n";
echo " ======================================== \n\n";

?>
The result Is:

Array
(
[FileName] => IMG_0743.JPG
[FileDateTime] => 1439766899
[FileSize] => 1175003
[FileType] => 2
[MimeType] => image/jpeg
[SectionsFound] => ANY_TAG, IFD0, EXIF
[COMPUTED] => Array
(
[html] => width="2592" height="1936"
[Height] => 1936
[Width] => 2592
[IsColor] => 1
[ByteOrderMotorola] => 1
[ApertureFNumber] => f/2.4
)

[Make] => Apple
[Model] => iPad mini 2
[Orientation] => 1
[XResolution] => 72/1
[YResolution] => 72/1
[ResolutionUnit] => 2
[Software] => 8.1
[DateTime] => 2015:08:16 16:14:59
[YCbCrPositioning] => 1
[ExposureTime] => 1/440
[FNumber] => 12/5
[ExposureProgram] => 2
[ISOSpeedRatings] => 32
[ExifVersion] => 0221
[DateTimeOriginal] => 2015:08:16 16:14:59
[DateTimeDigitized] => 2015:08:16 16:14:59
[ComponentsConfiguration] =>
[ShutterSpeedValue] => 6682/761
[ApertureValue] => 4845/1918
[BrightnessValue] => 9577/1196
[ExposureBiasValue] => 0/1
[MeteringMode] => 5
[Flash] => 32
[FocalLength] => 33/10
)

I get the following when the above is run without the exit().

PHP Notice: Undefined index: GPS.GPSLatitude in /home/rick/Pictures/exifPlay/getExif-GPS.php on line 11
PHP Notice: Undefined index: GPS.GPSLatitudeRef in /home/rick/Pictures/exifPlay/getExif-GPS.php on line 11
PHP Notice: Undefined offset: 1 in /home/rick/Pictures/exifPlay/getExif-GPS.php on line 22
PHP Notice: Undefined offset: 2 in /home/rick/Pictures/exifPlay/getExif-GPS.php on line 22
PHP Notice: Undefined index: GPS in /home/rick/Pictures/exifPlay/getExif-GPS.php on line 12
PHP Notice: Undefined index: GPS in /home/rick/Pictures/exifPlay/getExif-GPS.php on line 12
PHP Notice: Undefined offset: 1 in /home/rick/Pictures/exifPlay/getExif-GPS.php on line 22
PHP Notice: Undefined offset: 2 in /home/rick/Pictures/exifPlay/getExif-GPS.php on line 22

Latitude 0
Longitude 0




When I run pyExifToolGUI on this file I get this: See attached file.

How can I get PHP to show the GPS tags??

Thanks, R
Attached Thumbnails
Click image for larger version

Name:	Selection_105.png
Views:	34
Size:	88.2 KB
ID:	23844  

Last edited by pizzipie; 12-28-2016 at 02:28 PM.
 
Old 12-28-2016, 06:00 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Looking at the output of the array there isn't any GPS data which might be in another section. To see everything try:

Code:
$exif = exif_read_data($filename, NULL, true);
 
Old 12-29-2016, 10:38 AM   #3
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Original Poster
Rep: Reputation: 12
Thanks for the reply michaelk,

Quote:
Looking at the output of the array there isn't any GPS data which might be in another section. To see everything try:
When I try:

PHP Code:
$exif exif_read_data($filenameNULLtrue); 
This is the result:

PHP Notice: Undefined index: GPS.GPSLatitude in /home/rick/Pictures/exifPlay/getExif-GPS.php on line 11
PHP Notice: Undefined index: GPS.GPSLatitudeRef in /home/rick/Pictures/exifPlay/getExif-GPS.php on line 11
PHP Notice: Undefined offset: 1 in /home/rick/Pictures/exifPlay/getExif-GPS.php on line 22
PHP Notice: Undefined offset: 2 in /home/rick/Pictures/exifPlay/getExif-GPS.php on line 22
PHP Notice: Undefined index: GPS in /home/rick/Pictures/exifPlay/getExif-GPS.php on line 12
PHP Notice: Undefined index: GPS in /home/rick/Pictures/exifPlay/getExif-GPS.php on line 12
PHP Notice: Undefined offset: 1 in /home/rick/Pictures/exifPlay/getExif-GPS.php on line 22
PHP Notice: Undefined offset: 2 in /home/rick/Pictures/exifPlay/getExif-GPS.php on line 22

Latitude 0
Longitude 0

Running pyExifToolGUI on this file does show the Lat and Long and other GPS tags.
The Lat and Long are correct for this location;

Is there any way to specifically read exif GPS data only.
 
Old 12-29-2016, 11:00 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Looks like I was offtrack a bit. Took me a bit to figure out why GPS was not on my pictures...

The reason your not getting any GPS data is due to a security flaw in PHP. From some searching I believe the fix is in versions 5.6.25, 7.0.10

http://stackoverflow.com/questions/3...s-gps-location

Last edited by michaelk; 12-29-2016 at 03:34 PM.
 
1 members found this post helpful.
Old 12-29-2016, 07:27 PM   #5
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Original Poster
Rep: Reputation: 12
Thanks again michaelk,

I'll look into this and try to get the fix.

R
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading exif data from a C program billsee Programming 6 07-19-2016 09:11 PM
Reading EXIF data billsee Linux - Software 4 09-09-2014 12:17 AM
Read GPS Serial data from GPIO kinglizard86 Linux - Hardware 2 08-25-2014 02:50 AM
Need software to read Data from HOLUX GM-210 GPS receiver for Ubuntu 8.10 srinivasmiriyalu Linux - Software 7 06-18-2009 08:46 AM
Change Exif data in linux? shwouchk Linux - Software 2 12-02-2006 06:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration