25 private const SRGB_EXIF_COLOR_SPACE =
'sRGB';
26 private const SRGB_ICC_PROFILE_DESCRIPTION =
'sRGB IEC61966-2.1';
30 if ( !parent::normaliseParams( $image, $params ) ) {
33 if ( isset( $params[
'quality'] ) && !self::validateQuality( $params[
'quality'] ) ) {
41 if ( $name ===
'quality' ) {
42 return self::validateQuality( $value );
44 return parent::validateParam( $name, $value );
51 private static function validateQuality( $value ) {
52 return $value ===
'low';
58 $res = parent::makeParamString( $params );
59 if ( $res && isset( $params[
'quality'] ) ) {
60 $res =
"q{$params['quality']}-$res";
73 if ( preg_match(
'/q([^-]+)-(.*)$/', $str, $m ) ) {
75 if ( self::validateQuality( $v ) ) {
76 $res = parent::parseParamString( $m[2] );
82 $res = parent::parseParamString( $str );
89 $res = parent::getScriptParams( $params );
90 if ( isset( $params[
'quality'] ) ) {
91 $res[
'quality'] = $params[
'quality'];
100 if ( !is_array( $meta ) ) {
107 'width' => $meta[
'SOF'][
'width'] ?? 0,
108 'height' => $meta[
'SOF'][
'height'] ?? 0,
110 if ( isset( $meta[
'SOF'][
'bits'] ) ) {
111 $info[
'bits'] = $meta[
'SOF'][
'bits'];
114 unset( $meta[
'SOF'] );
115 $info[
'metadata'] = $meta;
118 wfDebug( __METHOD__ .
': ' . $e->getMessage() );
135 public function rotate( $file, $params ) {
136 $jpegTran = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::JpegTran );
138 $rotation = ( $params[
'rotation'] + $this->
getRotation( $file ) ) % 360;
140 if ( $jpegTran && is_executable( $jpegTran ) ) {
141 $command = Shell::command( $jpegTran,
151 if ( $result->getExitCode() !== 0 ) {
153 $result->getStdout(),
154 $command->__toString()
162 return parent::rotate( $file, $params );
172 $params = parent::sanitizeParamsForBucketing( $params );
175 unset( $params[
'quality'] );
184 $useTinyRGBForJPGThumbnails = MediaWikiServices::getInstance()
185 ->getMainConfig()->get( MainConfigNames::UseTinyRGBForJPGThumbnails );
187 $ret = parent::transformImageMagick( $image, $params );
193 if ( $useTinyRGBForJPGThumbnails ) {
206 $colorSpaces = [ self::SRGB_EXIF_COLOR_SPACE,
'-' ];
207 $profiles = [ self::SRGB_ICC_PROFILE_DESCRIPTION ];
212 if ( isset( $params[
'quality'] ) && $params[
'quality'] > 30 ) {
220 realpath( __DIR__ ) .
'/tinyrgb.icc'
239 array $oldProfileStrings, $profileFilepath
241 $exiftool = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::Exiftool );
243 if ( !$exiftool || !is_executable( $exiftool ) ) {
247 $result = Shell::command(
250 '-ICC_Profile:ProfileDescription',
259 $data = explode(
"\t", trim( $result->getStdout() ), 3 );
261 if ( $result->getExitCode() !== 0 ) {
267 $colorSpaceRegex =
'/' . preg_quote( $data[0],
'/' ) .
'/i';
268 if ( !preg_grep( $colorSpaceRegex, $colorSpaces ) ) {
273 $profileRegex =
'/' . preg_quote( $data[1],
'/' ) .
'/i';
274 if ( !preg_grep( $profileRegex, $oldProfileStrings ) ) {
279 $command = Shell::command( $exiftool,
280 '-overwrite_original',
281 '-icc_profile<=' . $profileFilepath,
288 if ( $result->getExitCode() !== 0 ) {
290 $result->getStdout(),
291 $command->__toString()
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)
to override array
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.If this returns null, the caller will fall back to getI...
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)
to override bool
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.