mirror of
https://github.com/processwire/processwire.git
synced 2025-08-08 15:57:01 +02:00
Some updates preparing for additonal webp options (new options not ready to use quite yet).
This commit is contained in:
@@ -622,7 +622,6 @@ $config->fileContentTypes = array(
|
||||
* #property int quality Image quality, enter a value between 1 and 100, where 100 is highest quality (and largest files)
|
||||
* #property float defaultGamma Default gamma of 0.5 to 4.0 or -1 to disable gamma correction (default=2.0)
|
||||
* #property bool webpAdd Create a WEBP copy with every new image variation? (default=false)
|
||||
* #property int webpQuality Quality setting of 1-100 where higher is better but bigger (default=90)
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
@@ -637,7 +636,24 @@ $config->imageSizerOptions = array(
|
||||
'hidpiQuality' => 60, // Same as above quality setting, but specific to hidpi images
|
||||
'defaultGamma' => 2.0, // defaultGamma: 0.5 to 4.0 or -1 to disable gamma correction (default=2.0)
|
||||
'webpAdd' => false, // set this to true, if the imagesizer engines should create a Webp copy with every (new) image variation
|
||||
'webpQuality' => 90, // webpQuality: 1-100 where higher is better but bigger
|
||||
);
|
||||
|
||||
/**
|
||||
* Options for webp images
|
||||
*
|
||||
* #property int quality Quality setting where 1-100 where higher is better but bigger
|
||||
* #property bool useSrcExt Use source file extension in webp filename? (file.jpg.webp rather than file.webp)
|
||||
* #property bool useSrcUrlOnSize Fallback to source file URL when webp file is larger than source?
|
||||
* #property bool useSrcUrlOnFail Fallback to source file URL when webp file fails for some reason?
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
*/
|
||||
$config->webpOptions = array(
|
||||
'quality' => 90, // Quality setting of 1-100 where higher is better but bigger
|
||||
'useSrcExt' => false, // Use source file extension in webp filename? (file.jpg.webp rather than file.webp)
|
||||
'useSrcUrlOnSize' => true, // Fallback to source file URL when webp file is larger than source?
|
||||
'useSrcUrlOnFail' => true, // Fallback to source file URL when webp file fails for some reason?
|
||||
);
|
||||
|
||||
/**
|
||||
|
@@ -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
|
||||
|
@@ -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 Pagefile’s 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;
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user