Permalink
Browse files

Fix EZP-27993: Support quality override by image alias (#1324)

  • Loading branch information...
peterkeung authored and andrerom committed Nov 22, 2017
1 parent ee65f38 commit f7dff9ec59b47c11e2c22ef958a14bf655bd7248
Showing with 43 additions and 1 deletion.
  1. +38 −1 lib/ezimage/classes/ezimagemanager.php
  2. +5 −0 settings/image.ini
@@ -98,6 +98,7 @@ public function __construct()
$this->MIMETypeSettingsMap = array();
$this->QualityValues = array();
$this->QualityValueMap = array();
$this->QualityValueMapOverride = array();
$ini = eZINI::instance( 'image.ini' );
$this->TemporaryImageDirPath = eZSys::cacheDirectory() . '/' . $ini->variable( 'FileSettings', 'TemporaryDir' );
@@ -177,6 +178,7 @@ function aliasList()
$alias = array( 'name' => 'original',
'reference' => false,
'mime_type' => false,
'quality' => false,
'filters' => array() );
$alias['alias_key'] = $this->createImageAliasKey( $alias );
$aliasList['original'] = $alias;
@@ -485,11 +487,31 @@ function appendQualityValue( $mimeType, $qualityValue )
*/
function qualityValue( $mimeType )
{
if ( isset( $this->QualityValueMap[$mimeType] ) )
if ( isset( $this->QualityValueMapOverride[$mimeType] ) )
return $this->QualityValueMapOverride[$mimeType]['value'];
else if ( isset( $this->QualityValueMap[$mimeType] ) )
return $this->QualityValueMap[$mimeType]['value'];
return false;
}
/*!
Sets a quality value override \a $qualityValue to the MIME-Type \a $mimeType in the context of an alias.
*/
function setQualityValueOverride( $mimeType, $qualityValue )
{
$element = array( 'name' => $mimeType,
'value' => $qualityValue );
$this->QualityValueMapOverride[$mimeType] = $element;
}
/*!
Reset the quality value override map if there is no alias or alias quality override
*/
function resetQualityValueOverride()
{
$this->QualityValueMapOverride = array();
}
/*!
Appends the MIME-Type setting \a $settings to the image system.
*/
@@ -747,11 +769,14 @@ function createAliasFromINI( $iniGroup )
$alias = array( 'name' => $iniGroup,
'reference' => false,
'mime_type' => false,
'quality' => false,
'filters' => array() );
if ( $ini->hasVariable( $iniGroup, 'Name' ) )
$alias['name'] = $ini->variable( $iniGroup, 'Name' );
if ( $ini->hasVariable( $iniGroup, 'MIMEType' ) )
$alias['mime_type'] = $ini->variable( $iniGroup, 'MIMEType' );
if ( $ini->hasVariable( $iniGroup, 'Quality' ) )
$alias['quality'] = $ini->variable( $iniGroup, 'Quality' );
if ( $ini->hasVariable( $iniGroup, 'Filters' ) )
{
$filters = array();
@@ -1048,6 +1073,7 @@ function convert( $sourceMimeData, &$destinationMimeData, $aliasName = false, $p
$filters = array();
$alias = false;
$this->resetQualityValueOverride();
if ( $aliasName )
{
$aliasList = $this->aliasList();
@@ -1059,6 +1085,17 @@ function convert( $sourceMimeData, &$destinationMimeData, $aliasName = false, $p
{
eZMimeType::changeMIMEType( $destinationMimeData, $alias['mime_type'] );
}
$qualityOverride = $alias['quality'];
if ( $qualityOverride )
{
foreach ( $qualityOverride as $qualityOverrideValue )
{
$elements = explode( ';', $qualityOverrideValue );
$mimeType = $elements[0];
$qualityValue = $elements[1];
$this->setQualityValueOverride( $mimeType, $qualityValue );
}
}
}
}
$mimeTypeOverride = $this->mimeTypeOverride( $sourceMimeData );
View
@@ -76,6 +76,11 @@ AliasList[]=rss
# to use image/jpeg for screenshot but rather image/png or image/gif.
# MIMEType=image/png
#
# Override quality by MIME type for this alias only
# This follows the pattern from the global [MIMETypeSettings] settings
# Quality[]
# Quality[]=image/jpeg;80
#
# A list of filters to run, each filter must be supported by the active image converters
# Filters[]=geometry/scale=300;300

0 comments on commit f7dff9e

Please sign in to comment.