pel / pel

PHP Exif Library - library for reading and writing Exif headers in JPEG and TIFF files using PHP.

Home Page:https://github.com/pel/pel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PelEntryRational does not respect decimal point for GPS_ALTITUDE

wencywww opened this issue · comments

The gps.php file within the examples has directions for adding GPS parameters to the exif data.
Lat/Lng are OK, but the altitude is added with the decimal point entirely stripped:
So, if you pass $altitude = 1234.56, the result saved is 123456.

/* * Add the altitude. The absolute value is stored here, the sign is * stored in the GPS_ALTITUDE_REF tag below. */ $gps_ifd->addEntry(new PelEntryRational(PelTag::GPS_ALTITUDE, [ abs($altitude), 1 ]));

Can you confirm?

did you find any solution ?

I've found a simple, solution :)
replace this line
$gps_ifd->addEntry(new PelEntryRational(PelTag::GPS_ALTITUDE, [ abs($altitude), 1 ]));
by:

$todevide = 1;
$decimal = strlen(substr(strrchr($altitude, "."), 1));
for ($i = 1; $i <= $decimal; $i++) {
$todevide = $todevide * 10;
}
echo $todevide;
$gps_ifd->addEntry(new PelEntryRational(PelTag::GPS_ALTITUDE, [
abs($altitude),
$todevide
]));