Commit b278302a authored by Sigrid Suski's avatar Sigrid Suski

(+) webp_quality config key for WEBP images added

parent 8f93196e
......@@ -35,6 +35,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
(+) Added support for WEBP images into Grafika
(+) Introducing of semantic versioning
(+) webp_quality config key for WEBP images added
(!) Image->saveAs() creates editor object if it not already exists
......
......@@ -141,9 +141,10 @@ class Image extends File
if ( !$this->image ) {
$this->createEditor();
}
$quality = ( $type == 'WEBP' ) ? Framework::Cfg( 'image.webp_quality', 80 ) : Framework::Cfg( 'image.jpeg_quality', 90 );
return $this->editor
->save( $this->image, $path, $type, Framework::Cfg( 'image.quality', 90 ) );
->save( $this->image, $path, $type, $quality );
}
/**
......@@ -155,9 +156,10 @@ class Image extends File
public function save( $type = null )
{
$this->createEditor();
$quality = ( $type == 'webp' ) ? Framework::Cfg( 'image.webp_quality', 80 ) : Framework::Cfg( 'image.jpeg_quality', 90 );
return $this->editor
->save( $this->image, $this->_filename, $type, Framework::Cfg( 'image.quality', 90 ) );
->save( $this->image, $this->_filename, $type, $quality );
}
/**
......
......@@ -747,7 +747,7 @@ final class Editor implements EditorInterface
* @param Image $image
* @param string $file File path where to save the image.
* @param null|string $type Type of image. Can be null, "GIF", "PNG", or "JPEG".
* @param null|string $quality Quality of image. Applies to JPEG only. Accepts number 0 - 100 where 0 is lowest and 100 is the highest quality. Or null for
* @param null|string $quality Quality of image. Applies to JPEG and WEBP only. Accepts number 0 - 100 where 0 is lowest and 100 is the highest quality. Or null for
* default.
* @param bool|false $interlace Set to true for progressive JPEG. Applies to JPEG only.
* @param int $permission Default permission when creating non-existing target directory.
......@@ -790,6 +790,9 @@ final class Editor implements EditorInterface
case ImageType::WEBP:
if ( function_exists( 'imagewebp' ) ) {
$quality = ( $quality === null ) ? 75 : $quality; // Default to 75 (GDs default) if null.
$quality = ( $quality > 100 ) ? 100 : $quality;
$quality = ( $quality < 0 ) ? 0 : $quality;
imagewebp( $image->getCore(), $file, $quality );
}
else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment