X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fmedia%2FJpeg.php;h=fbdbdfe31e8f9c232bc71f7760250787542d29e6;hb=d6aae24d77adff00854683b99647928952ed3059;hp=ee7eff86ec42ccc98886c31c260b53e83577fd4b;hpb=6a06b39dc99b47d59485771f2720a37ae8728259;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/media/Jpeg.php b/includes/media/Jpeg.php index ee7eff86ec..fbdbdfe31e 100644 --- a/includes/media/Jpeg.php +++ b/includes/media/Jpeg.php @@ -31,6 +31,71 @@ * @ingroup Media */ class JpegHandler extends ExifBitmapHandler { + + function normaliseParams( $image, &$params ) { + if ( !parent::normaliseParams( $image, $params ) ) { + return false; + } + if ( isset( $params['quality'] ) && !self::validateQuality( $params['quality'] ) ) { + return false; + } + return true; + } + + function validateParam( $name, $value ) { + if ( $name === 'quality' ) { + return self::validateQuality( $value ); + } else { + return parent::validateParam( $name, $value ); + } + } + + /** Validate and normalize quality value to be between 1 and 100 (inclusive). + * @param int $value Quality value, will be converted to integer or 0 if invalid + * @return bool True if the value is valid + */ + private static function validateQuality( $value ) { + return $value === 'low'; + } + + function makeParamString( $params ) { + // Prepend quality as "qValue-". This has to match parseParamString() below + $res = parent::makeParamString( $params ); + if ( $res && isset( $params['quality'] ) ) { + $res = "q{$params['quality']}-$res"; + } + return $res; + } + + function parseParamString( $str ) { + // $str contains "qlow-200px" or "200px" strings because thumb.php would strip the filename + // first - check if the string begins with "qlow-", and if so, treat it as quality. + // Pass the first portion, or the whole string if "qlow-" not found, to the parent + // The parsing must match the makeParamString() above + $res = false; + $m = false; + if ( preg_match( '/q([^-]+)-(.*)$/', $str, $m ) ) { + $v = $m[1]; + if ( self::validateQuality( $v ) ) { + $res = parent::parseParamString( $m[2] ); + if ( $res ) { + $res['quality'] = $v; + } + } + } else { + $res = parent::parseParamString( $str ); + } + return $res; + } + + function getScriptParams( $params ) { + $res = parent::getScriptParams( $params ); + if ( isset( $params['quality'] ) ) { + $res['quality'] = $params['quality']; + } + return $res; + } + function getMetadata( $image, $filename ) { try { $meta = BitmapMetadataHandler::Jpeg( $filename ); @@ -80,8 +145,7 @@ class JpegHandler extends ExifBitmapHandler { wfDebug( __METHOD__ . ": running jpgtran: $cmd\n" ); wfProfileIn( 'jpegtran' ); $retval = 0; - // @todo FIXME Undefined variable $env - $err = wfShellExecWithStderr( $cmd, $retval, $env ); + $err = wfShellExecWithStderr( $cmd, $retval ); wfProfileOut( 'jpegtran' ); if ( $retval !== 0 ) { $this->logErrorForExternalProcess( $retval, $err, $cmd ); @@ -94,4 +158,19 @@ class JpegHandler extends ExifBitmapHandler { return parent::rotate( $file, $params ); } } + + public function supportsBucketing() { + return true; + } + + public function sanitizeParamsForBucketing( $params ) { + $params = parent::sanitizeParamsForBucketing( $params ); + + // Quality needs to be cleared for bucketing. Buckets need to be default quality + if ( isset( $params['quality'] ) ) { + unset( $params['quality'] ); + } + + return $params; + } }