Git Product home page Git Product logo

batch-renamer's People

Contributors

ocram avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

batch-renamer's Issues

Create placeholder inside EXIF recording time section (“%er…”) that tries to detect missing EXIF time zone from file modification time

$diff = \DateTime::createFromFormat('U', $fileObj->getMTime())->diff($dateTimeObj);
$sign = $diff->invert === 0 ? '+' : '-';
$hours = (int) \round($diff->y * 12 * 30.436875 * 24 + $diff->m * 30.436875 * 24 + $diff->d * 24 + $diff->h);
$minutes = (int) \round($diff->i + $diff->s / 60);

return $sign . \sprintf('%02d', $hours) . ':' . \sprintf('%02d', $minutes);

Provide variant of EXIF recording time (“%er…”) that considers EXIF time zone where available (EXIF 2.31+)

if ($field[0] === 'EXIF' && $field[1] === 'DateTimeOriginal') {
	$utcOffset = !empty($exif['EXIF']['UndefinedTag:0x9011']) ? (string) $exif['EXIF']['UndefinedTag:0x9011'] : null;
}
elseif ($field[0] === 'EXIF' && $field[1] === 'DateTimeDigitized') {
	$utcOffset = !empty($exif['EXIF']['UndefinedTag:0x9012']) ? (string) $exif['EXIF']['UndefinedTag:0x9012'] : null;
}
elseif ($field[0] === 'IFD0' && $field[1] === 'DateTime') {
	$utcOffset = !empty($exif['EXIF']['UndefinedTag:0x9010']) ? (string) $exif['EXIF']['UndefinedTag:0x9010'] : null;
}
else {
	$utcOffset = null;
}

$timeZone = null;

if ($utcOffset !== null) {
	if (\preg_match('/^([+-])([01][0-9]):([0134][05])$/', $utcOffset) === 1) {
		$timeZone = new \DateTimeZone($utcOffset);
	}
}

// $dateTimeObj = ... // add $timeZone as parameter

$dateTimeObj->setTimeZone(new DateTimeZone(\date_default_timezone_get()));

if ($timeOffsetObj !== null) {
	// ...
}

Create placeholder inside EXIF recording time section (“%er…”) that tries to detect missing EXIF time zone from GPS time (UTC)

if (!empty($exif['GPS']) && !empty($exif['GPS']['GPSDateStamp']) && !empty($exif['GPS']['GPSTimeStamp'])) {
    if (\count($exif['GPS']['GPSTimeStamp']) === 3) {
        $gpsFixTimeComponents = [];

        for ($i = 0; $i < 3; $i++) {
            if (\preg_match('/^([0-9]+)(?:\/([0-9.]+))?$/', $exif['GPS']['GPSTimeStamp'][$i], $matches) === 1) {
                if ($matches[2] !== '0' && $matches[2] !== '0.0') {
                    $gpsFixTimeComponents[] = (int) (((int) $matches[1]) / ((float) $matches[2]));
                }
                else {
                    return \UNKNOWN_INFORMATION_MARKER;
                }
            }
        }

        $gpsFixDateTimeObj = \DateTime::createFromFormat(
            \EXIF_DATE_AND_TIME_FORMAT,
            $exif['GPS']['GPSDateStamp'] . ' ' . \sprintf('%02d:%02d:%02d', ...$gpsFixTimeComponents)
        );

        if ($gpsFixDateTimeObj !== false) {
            $diff = $gpsFixDateTimeObj->diff($dateTimeObj);
            $sign = $diff->invert === 0 ? '+' : '-';
            $hours = (int) \round($diff->y * 12 * 30.436875 * 24 + $diff->m * 30.436875 * 24 + $diff->d * 24 + $diff->h);
            $minutes = (int) \round($diff->i + $diff->s / 60);

            if ($minutes === 60) {
                $hours++;
                $minutes = 0;
            }

            return $sign . \sprintf('%02d', $hours) . ':' . \sprintf('%02d', $minutes);
        }
        else {
            return \UNKNOWN_INFORMATION_MARKER;
        }
    }
    else {
        return \UNKNOWN_INFORMATION_MARKER;
    }
}
else {
    return \UNKNOWN_INFORMATION_MARKER;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.