39 private const SRGB_EXIF_COLOR_SPACE =
'sRGB';
40 private const SRGB_ICC_PROFILE_DESCRIPTION =
'sRGB IEC61966-2.1';
43 if ( !parent::normaliseParams( $image, $params ) ) {
46 if ( isset( $params[
'quality'] ) && !self::validateQuality( $params[
'quality'] ) ) {
53 if ( $name ===
'quality' ) {
54 return self::validateQuality( $value );
56 return parent::validateParam( $name, $value );
63 private static function validateQuality( $value ) {
64 return $value ===
'low';
69 $res = parent::makeParamString( $params );
70 if ( $res && isset( $params[
'quality'] ) ) {
71 $res =
"q{$params['quality']}-$res";
83 if ( preg_match(
'/q([^-]+)-(.*)$/', $str, $m ) ) {
85 if ( self::validateQuality( $v ) ) {
86 $res = parent::parseParamString( $m[2] );
92 $res = parent::parseParamString( $str );
98 $res = parent::getScriptParams( $params );
99 if ( isset( $params[
'quality'] ) ) {
100 $res[
'quality'] = $params[
'quality'];
108 if ( !is_array( $meta ) ) {
115 'width' => $meta[
'SOF'][
'width'] ?? 0,
116 'height' => $meta[
'SOF'][
'height'] ?? 0,
118 if ( isset( $meta[
'SOF'][
'bits'] ) ) {
119 $info[
'bits'] = $meta[
'SOF'][
'bits'];
122 unset( $meta[
'SOF'] );
123 $info[
'metadata'] = $meta;
126 wfDebug( __METHOD__ .
': ' . $e->getMessage() );
143 public function rotate( $file, $params ) {
144 $jpegTran = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::JpegTran );
146 $rotation = ( $params[
'rotation'] + $this->
getRotation( $file ) ) % 360;
148 if ( $jpegTran && is_executable( $jpegTran ) ) {
149 $command = Shell::command( $jpegTran,
159 if ( $result->getExitCode() !== 0 ) {
161 $result->getStdout(),
170 return parent::rotate( $file, $params );
178 $params = parent::sanitizeParamsForBucketing( $params );
181 unset( $params[
'quality'] );
190 $useTinyRGBForJPGThumbnails = MediaWikiServices::getInstance()
191 ->getMainConfig()->get( MainConfigNames::UseTinyRGBForJPGThumbnails );
193 $ret = parent::transformImageMagick( $image, $params );
199 if ( $useTinyRGBForJPGThumbnails ) {
212 $colorSpaces = [ self::SRGB_EXIF_COLOR_SPACE,
'-' ];
213 $profiles = [ self::SRGB_ICC_PROFILE_DESCRIPTION ];
218 if ( isset( $params[
'quality'] ) && $params[
'quality'] > 30 ) {
226 realpath( __DIR__ ) .
'/tinyrgb.icc'
245 array $oldProfileStrings, $profileFilepath
247 $exiftool = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::Exiftool );
249 if ( !$exiftool || !is_executable( $exiftool ) ) {
253 $result = Shell::command(
256 '-ICC_Profile:ProfileDescription',
265 $data = explode(
"\t", trim( $result->getStdout() ), 3 );
267 if ( $result->getExitCode() !== 0 ) {
273 $colorSpaceRegex =
'/' . preg_quote( $data[0],
'/' ) .
'/i';
274 if ( !preg_grep( $colorSpaceRegex, $colorSpaces ) ) {
279 $profileRegex =
'/' . preg_quote( $data[1],
'/' ) .
'/i';
280 if ( !preg_grep( $profileRegex, $oldProfileStrings ) ) {
285 $command = Shell::command( $exiftool,
286 '-overwrite_original',
287 '-icc_profile<=' . $profileFilepath,
294 if ( $result->getExitCode() !== 0 ) {
296 $result->getStdout(),
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Stuff specific to JPEG and (built-in) TIFF handler.
applyExifRotation( $info, $metadata)
getRotation( $file)
On supporting image formats, try to read out the low-level orientation of the file and return the ang...
const BROKEN_FILE
Error extracting metadata.
static version()
The version of the output format.
makeParamString( $params)
Merge a parameter array into a string appropriate for inclusion in filenames.stringto override to ove...
validateParam( $name, $value)
Validate a thumbnail parameter at parse time.Return true to accept the parameter, and false to reject...
getScriptParams( $params)
swapICCProfile( $filepath, array $colorSpaces, array $oldProfileStrings, $profileFilepath)
Swaps an embedded ICC profile for another, if found.
getSizeAndMetadata( $state, $filename)
Get image size information and metadata array.
supportsBucketing()
Returns whether or not this handler supports the chained generation of thumbnails according to bucket...
parseParamString( $str)
Parse a param string made with makeParamString back into an array.array|false Array of parameters or ...
sanitizeParamsForBucketing( $params)
Returns a normalised params array for which parameters have been cleaned up for bucketing purposes....
normaliseParams( $image, &$params)
transformImageMagick( $image, $params)
Transform an image using ImageMagick.to overrideMediaTransformError|false Error object if error occur...
A class containing constants representing the names of configuration variables.