Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Pinnokkio opened this issue Jan 26, 2025 · 0 comments
Open

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

Pinnokkio opened this issue Jan 26, 2025 · 0 comments

Comments

@Pinnokkio
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant