1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-16 11:44:42 +02:00

Some updates preparing for additonal webp options (new options not ready to use quite yet).

This commit is contained in:
Ryan Cramer
2019-06-30 11:01:23 -04:00
parent f1913df4d4
commit 2b0d8f333a
4 changed files with 35 additions and 9 deletions

View File

@@ -40,6 +40,7 @@
* @property bool $protectCSRF Enables CSRF (cross site request forgery) protection on all PW forms, recommended for security. #pw-group-HTTP-and-input
*
* @property array $imageSizerOptions Options to set image sizing defaults. Please see the /wire/config.php file for all options and defaults. #pw-group-images
* @property array $webpOptions Options for webp images. Please see /wire/config.php for all options. #pw-group-images
*
* @property bool $pagefileSecure When used, files in /site/assets/files/ will be protected with the same access as the page. Routines files through a passthrough script. #pw-group-files
* @property string $pagefileSecurePathPrefix One or more characters prefixed to the pathname of protected file dirs. This should be some prefix that the .htaccess file knows to block requests for. #pw-group-files

View File

@@ -22,6 +22,7 @@
* =======================================================================
* @property bool $useSrcUrlOnFail Use source Pagefile URL if extra image does not exist and cannot be created? (default=false)
* @property bool $useSrcUrlOnSize Use source Pagefile URL if extra file is larger than source file? (default=false)
* @property bool $useSrcExt Use longer filenames that also include the Pagefiles extension? (default=false)
*
* Hookable methods
* ================
@@ -64,6 +65,7 @@ class PagefileExtra extends WireData {
$this->setExtension($extension);
$this->useSrcUrlOnFail = true;
$this->useSrcUrlOnSize = false;
$this->useSrcExt = false;
return parent::__construct();
}
@@ -117,7 +119,9 @@ class PagefileExtra extends WireData {
*/
public function filename() {
$pathinfo = pathinfo($this->pagefile->filename());
$filename = $pathinfo['dirname'] . '/' . $pathinfo['filename'] . '.' . $this->extension;
$ext = '.' . $this->extension;
if($this->useSrcExt) $ext = '.' . $pathinfo['extension'] . $ext;
$filename = $pathinfo['dirname'] . '/' . $pathinfo['filename'] . $ext;
if(empty($this->filenamePrevious)) $this->filenamePrevious = $filename;
return $filename;
}
@@ -151,7 +155,9 @@ class PagefileExtra extends WireData {
$url = $this->pagefile->url();
} else {
$pathinfo = pathinfo($this->pagefile->url());
$url = $pathinfo['dirname'] . '/' . $pathinfo['filename'] . '.' . $this->extension;
$ext = '.' . $this->extension;
if($this->useSrcExt) $ext = '.' . $pathinfo['extension'] . $ext;
$url = $pathinfo['dirname'] . '/' . $pathinfo['filename'] . $ext;
}
return $url;

View File

@@ -685,6 +685,8 @@ class Pageimage extends Pagefile {
$config = $this->wire('config');
$debug = $config->debug;
$configOptions = $config->imageSizerOptions;
$webpOptions = $config->webpOptions;
if(!empty($webpOptions['quality'])) $defaultOptions['webpQuality'] = $webpOptions['quality'];
if(!is_array($configOptions)) $configOptions = array();
$options = array_merge($defaultOptions, $configOptions, $options);
@@ -772,11 +774,13 @@ class Pageimage extends Pagefile {
$filenameFinal = $this->pagefiles->path() . $basename;
$filenameFinalExists = file_exists($filenameFinal);
if(!empty($options['webpName'])) {
$filenameFinalWebp = $this->pagefiles->path() . basename($options['webpName'], '.webp') . '.webp';
} else if(!empty($webpOptions['useSrcExt'])) {
$filenameFinalWebp = $this->pagefiles->path() . $basename . '.webp'; // file.jpg.webp
} else {
$filenameFinalWebp = $this->pagefiles->path() . $basenameNoExt . '.webp';
$filenameFinalWebp = $this->pagefiles->path() . $basenameNoExt . '.webp'; // file.webp
}
// force new creation if requested webp copy doesn't exist, (regardless if regular variation exists or not)
@@ -1913,8 +1917,7 @@ class Pageimage extends Pagefile {
$webp = $this->extras('webp');
if(!$webp) {
$webp = new PagefileExtra($this, 'webp');
$webp->useSrcUrlOnFail = true; // use this pagefile URL instead if we fail to create a webp
$webp->useSrcUrlOnSize = true; // use webp URL only if it results in a smaller file
$webp->setArray($this->wire('config')->webpOptions);
$this->extras('webp', $webp);
$webp->addHookAfter('create', $this, 'hookWebpCreate');
}
@@ -1945,7 +1948,7 @@ class Pageimage extends Pagefile {
$original = $this;
$options = array(
'allowOriginal' => false,
'webpName' => basename($this->basename(), ".$this->ext"),
'webpName' => $webp->useSrcExt ? $this->basename() : basename($this->basename(), ".$this->ext"),
'webpOnly' => true
);
$width = $this->width;