Skip to content

Commit

Permalink
Refactor EXIF float calculation and shutter speed output
Browse files Browse the repository at this point in the history
  • Loading branch information
arnowelzel committed Jan 12, 2024
1 parent 2664b43 commit ae49cdd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lightbox-photoswipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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".
Expand Down
25 changes: 16 additions & 9 deletions src/LightboxPhotoSwipe/ExifHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}
Expand Down Expand Up @@ -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]);
}
}
4 changes: 2 additions & 2 deletions src/LightboxPhotoSwipe/LightboxPhotoSwipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'/';
Expand Down

0 comments on commit ae49cdd

Please sign in to comment.