mirror of
https://github.com/processwire/processwire.git
synced 2025-08-18 04:22:10 +02:00
added method and property webpFilename
This commit is contained in:
@@ -188,13 +188,28 @@ class Pageimage extends Pagefile {
|
|||||||
*/
|
*/
|
||||||
public function webpUrl() {
|
public function webpUrl() {
|
||||||
if(!$this->hasWebp()) {
|
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);
|
$path_parts = pathinfo($this->url);
|
||||||
$webpUrl = $path_parts['dirname'] . '/' . $path_parts['filename'] . '.webp';
|
$webpUrl = $path_parts['dirname'] . '/' . $path_parts['filename'] . '.webp';
|
||||||
return $webpUrl;
|
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
|
* Return if this image file has a webP dependency file
|
||||||
*
|
*
|
||||||
@@ -432,6 +447,9 @@ class Pageimage extends Pagefile {
|
|||||||
case 'srcWebp':
|
case 'srcWebp':
|
||||||
$value = $this->webpUrl();
|
$value = $this->webpUrl();
|
||||||
break;
|
break;
|
||||||
|
case 'webpFilename':
|
||||||
|
$value = $this->webpFilename();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
$value = parent::get($key);
|
$value = parent::get($key);
|
||||||
}
|
}
|
||||||
@@ -1905,7 +1923,7 @@ class Pageimage extends Pagefile {
|
|||||||
if($this->hasWebp()) {
|
if($this->hasWebp()) {
|
||||||
$info['webp']['hasWebp'] = true;
|
$info['webp']['hasWebp'] = true;
|
||||||
$info['webp']['webpUrl'] = $this->webpUrl;
|
$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 {
|
} else {
|
||||||
$info['webp']['hasWebp'] = false;
|
$info['webp']['hasWebp'] = false;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user