From a4431829d9756c1eec5649c24ff689b3db27d3e2 Mon Sep 17 00:00:00 2001 From: horst-n Date: Sat, 27 Apr 2019 10:37:10 +0200 Subject: [PATCH] added method and property webpFilename --- wire/core/Pageimage.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/wire/core/Pageimage.php b/wire/core/Pageimage.php index 50b4d619..2a5b3a41 100644 --- a/wire/core/Pageimage.php +++ b/wire/core/Pageimage.php @@ -188,13 +188,28 @@ class Pageimage extends Pagefile { */ public function webpUrl() { if(!$this->hasWebp()) { - return '#'; // @Ryan: what should be returned for none existing webp variations here? + return '#'; // @Ryan: what should be returned for none existing webp variations here? } $path_parts = pathinfo($this->url); $webpUrl = $path_parts['dirname'] . '/' . $path_parts['filename'] . '.webp'; return $webpUrl; } + /** + * Return the filesystem path to this image files webP dependency + * + * @return string + * + */ + public function webpFilename() { + if(!$this->hasWebp()) { + return ''; + } + $path_parts = pathinfo($this->filename); + $webpFilename = $path_parts['dirname'] . '/' . $path_parts['filename'] . '.webp'; + return $webpFilename; + } + /** * Return if this image file has a webP dependency file * @@ -432,6 +447,9 @@ class Pageimage extends Pagefile { case 'srcWebp': $value = $this->webpUrl(); break; + case 'webpFilename': + $value = $this->webpFilename(); + break; default: $value = parent::get($key); } @@ -1905,7 +1923,7 @@ class Pageimage extends Pagefile { if($this->hasWebp()) { $info['webp']['hasWebp'] = true; $info['webp']['webpUrl'] = $this->webpUrl; - $info['webp']['webpFilesize'] = filesize(dirname($this->filename) . '/' . pathinfo($this->filename, \PATHINFO_FILENAME) . '.webp'); + $info['webp']['webpFilesize'] = filesize($this->webpFilename()); } else { $info['webp']['hasWebp'] = false; }