Skip to content

Argument #1 ($number) must be of type int, float given #34

@Pinnokkio

Description

@Pinnokkio

When using your gps example, I'm getting the following error:
lsolesen\pel\PelEntryLong::numberToBytes(): Argument #1 ($number) must be of type int, float given, called in D:\...\vendor\fileeye\pel\src\PelEntryNumber.php on line 189

For example:

self::addGPS($filePath, 6.155703734, 46.20501537);



private static function addGPS($absoluteFilePath, float $longitude, float $latitude): void {
    $jpeg = new PelJpeg($absoluteFilePath);
    
    $exif = new PelExif();
    $jpeg->setExif($exif);
    
    $tiff = new PelTiff();
    $exif->setTiff($tiff);
    
    $ifd0 = new PelIfd(PelIfd::IFD0);
    $tiff->setIfd($ifd0);
    
    $gps_ifd = new PelIfd(PelIfd::GPS);
    $ifd0->addSubIfd($gps_ifd);
    
    $inter_ifd = new PelIfd(PelIfd::INTEROPERABILITY);
    $ifd0->addSubIfd($inter_ifd);
    
    $inter_ifd = new PelIfd(PelIfd::INTEROPERABILITY);
    $ifd0->addSubIfd($inter_ifd);
    
    $gps_ifd->addEntry(new PelEntryByte(PelTag::GPS_VERSION_ID, 2, 2, 0, 0));
    
    [$hours, $minutes, $seconds] = self::convertDecimalToDMS($latitude);
    $latitude_ref = ($latitude < 0) ? 'S' : 'N';
    
    $gps_ifd->addEntry(new PelEntryAscii(PelTag::GPS_LATITUDE_REF, $latitude_ref));
    $gps_ifd->addEntry(new PelEntryRational(PelTag::GPS_LATITUDE, $hours, $minutes, $seconds));
    
    [$hours, $minutes, $seconds] = self::convertDecimalToDMS($longitude);
    $longitude_ref = ($longitude < 0) ? 'W' : 'E';
    
    $gps_ifd->addEntry(new PelEntryAscii(PelTag::GPS_LONGITUDE_REF, $longitude_ref));
    $gps_ifd->addEntry(new PelEntryRational(PelTag::GPS_LONGITUDE, $hours, $minutes, $seconds));
    
    file_put_contents($absoluteFilePath, $jpeg->getBytes());
}



private static function convertDecimalToDMS(float $degree): ?array {
    if($degree > 180 || $degree < -180) {
        return null;
    }

    $degree = abs($degree);
    $seconds = $degree * 3600;

    $degrees = floor($degree);
    $seconds -= $degrees * 3600;

    $minutes = floor($seconds / 60);
    $seconds -= $minutes * 60;

    $seconds = round($seconds * 100, 0);

    return [
        [$degrees, 1],
        [$minutes, 1],
        [$seconds, 100],
    ];
}

Any ways to fix this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions