From ae49cdd02008d52ee24c45baf674a841bb2adabb Mon Sep 17 00:00:00 2001 From: Arno Welzel Date: Fri, 12 Jan 2024 12:42:50 +0100 Subject: [PATCH] Refactor EXIF float calculation and shutter speed output --- lightbox-photoswipe.php | 2 +- readme.txt | 6 ++++- src/LightboxPhotoSwipe/ExifHelper.php | 25 ++++++++++++------- src/LightboxPhotoSwipe/LightboxPhotoSwipe.php | 4 +-- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/lightbox-photoswipe.php b/lightbox-photoswipe.php index 6c11710..38c821e 100644 --- a/lightbox-photoswipe.php +++ b/lightbox-photoswipe.php @@ -3,7 +3,7 @@ Plugin Name: Lightbox with PhotoSwipe Plugin URI: https://wordpress.org/plugins/lightbox-photoswipe/ Description: Lightbox with PhotoSwipe -Version: 5.1.1 +Version: 5.1.2 Author: Arno Welzel Author URI: http://arnowelzel.de Text Domain: lightbox-photoswipe diff --git a/readme.txt b/readme.txt index 7544f42..f5e850a 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Contributors: awelzel Tags: attachments, images, gallery, lightbox, fancybox, photoswipe Requires at least: 5.3 Tested up to: 6.3 -Stable tag: 5.1.1 +Stable tag: 5.1.2 Donate link: https://paypal.me/ArnoWelzel License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -219,6 +219,10 @@ If you change any of the stylesheets or frontend scripts in `src/js` or `src/lib == Changelog == += 5.1.2 = + +* Updated handling of EXIF data shutter speed for fractional values with more than 1s. + = 5.1.1 = * Fix output of EXIF data shutter speed: instead of "123/1s" it will now be displayed as "123s" without "/1". diff --git a/src/LightboxPhotoSwipe/ExifHelper.php b/src/LightboxPhotoSwipe/ExifHelper.php index 244b884..f6b8234 100644 --- a/src/LightboxPhotoSwipe/ExifHelper.php +++ b/src/LightboxPhotoSwipe/ExifHelper.php @@ -67,13 +67,22 @@ function getFocalLength() */ function getShutter() { + // Variant 1: ExposureTime as numerator/denominator (e.g. "1/50" or "35/10") if (isset($this->exifData['EXIF']['ExposureTime'])) { - $exposureTime = $this->exifData['EXIF']['ExposureTime']; - if (substr($exposureTime, -2) === '/1') { - $exposureTime = substr($exposureTime, 0, -2); + $parts = explode('/', $this->exifData['EXIF']['ExposureTime']); + // Exposure times with a numerator of more than 1 will always be + // displays as float value with 2 decimals maximum (e.g. 35/10 = "3.5s" or 60/1 = "60s" etc.) + if ((float) $parts[0] != 1) { + if ((float) $parts[1] == 0) { + return ''; + } + return round((float) $parts[0] / (float) $parts[1], 2) . 's'; } - return $exposureTime . 's'; + // Numerator is 1, then return as fraction like "1/30s" or "1/4s" etc. + return $parts[0] . '/' . $parts[1] . 's'; } + + // Variant 2: ShutterSpeedValue as APEX value if (!isset($this->exifData['EXIF']['ShutterSpeedValue'])) { return ''; } @@ -177,12 +186,10 @@ private function addToCaption(&$output, $detail, $cssclass) */ private function exifGetFloat($value) { - $pos = strpos($value, '/'); - if ($pos === false) { + $parts = explode('/', $value); + if (!isset($parts[1])) { return (float) $value; } - $a = (float) substr($value, 0, $pos); - $b = (float) substr($value, $pos+1); - return ($b == 0) ? ($a) : ($a / $b); + return ($parts[1] == 0) ? (float) $parts[0] : (float) ($parts[0] / $parts[1]); } } diff --git a/src/LightboxPhotoSwipe/LightboxPhotoSwipe.php b/src/LightboxPhotoSwipe/LightboxPhotoSwipe.php index 2821a03..b50b81a 100644 --- a/src/LightboxPhotoSwipe/LightboxPhotoSwipe.php +++ b/src/LightboxPhotoSwipe/LightboxPhotoSwipe.php @@ -11,9 +11,9 @@ */ class LightboxPhotoSwipe { - const VERSION = '5.1.1'; + const VERSION = '5.1.2'; const SLUG = 'lightbox-photoswipe'; - const META_VERSION = '12'; + const META_VERSION = '14'; const CACHE_EXPIRE_IMG_DETAILS = 86400; const DB_VERSION = 36; const BASEPATH = WP_PLUGIN_DIR.'/'.self::SLUG.'/';