38 private const SRGB_EXIF_COLOR_SPACE =
'sRGB';
39 private const SRGB_ICC_PROFILE_DESCRIPTION =
'sRGB IEC61966-2.1';
42 if ( !parent::normaliseParams( $image, $params ) ) {
45 if ( isset( $params[
'quality'] ) && !self::validateQuality( $params[
'quality'] ) ) {
52 if ( $name ===
'quality' ) {
53 return self::validateQuality( $value );
55 return parent::validateParam( $name, $value );
62 private static function validateQuality( $value ) {
63 return $value ===
'low';
68 $res = parent::makeParamString( $params );
69 if (
$res && isset( $params[
'quality'] ) ) {
70 $res =
"q{$params['quality']}-$res";
82 if ( preg_match(
'/q([^-]+)-(.*)$/', $str, $m ) ) {
84 if ( self::validateQuality( $v ) ) {
85 $res = parent::parseParamString( $m[2] );
91 $res = parent::parseParamString( $str );
97 $res = parent::getScriptParams( $params );
98 if ( isset( $params[
'quality'] ) ) {
99 $res[
'quality'] = $params[
'quality'];
107 if ( !is_array( $meta ) ) {
109 throw new MWException(
'Metadata array is not an array' );
114 'width' => $meta[
'SOF'][
'width'] ?? 0,
115 'height' => $meta[
'SOF'][
'height'] ?? 0,
117 if ( isset( $meta[
'SOF'][
'bits'] ) ) {
118 $info[
'bits'] = $meta[
'SOF'][
'bits'];
121 unset( $meta[
'SOF'] );
122 $info[
'metadata'] = $meta;
127 wfDebug( __METHOD__ .
': ' . $e->getMessage() );
145 $jpegTran = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::JpegTran );
149 if ( $jpegTran && is_executable( $jpegTran ) ) {
150 $command = Shell::command( $jpegTran,
160 if ( $result->getExitCode() !== 0 ) {
162 $result->getStdout(),
171 return parent::rotate(
$file, $params );
179 $params = parent::sanitizeParamsForBucketing( $params );
182 unset( $params[
'quality'] );
191 $useTinyRGBForJPGThumbnails = MediaWikiServices::getInstance()
192 ->getMainConfig()->get( MainConfigNames::UseTinyRGBForJPGThumbnails );
194 $ret = parent::transformImageMagick( $image, $params );
200 if ( $useTinyRGBForJPGThumbnails ) {
213 $colorSpaces = [ self::SRGB_EXIF_COLOR_SPACE,
'-' ];
214 $profiles = [ self::SRGB_ICC_PROFILE_DESCRIPTION ];
219 if ( isset( $params[
'quality'] ) && $params[
'quality'] > 30 ) {
227 realpath( __DIR__ ) .
'/tinyrgb.icc'
246 array $oldProfileStrings, $profileFilepath
248 $exiftool = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::Exiftool );
250 if ( !$exiftool || !is_executable( $exiftool ) ) {
254 $result = Shell::command(
257 '-ICC_Profile:ProfileDescription',
266 $data = explode(
"\t", trim( $result->getStdout() ), 3 );
268 if ( $result->getExitCode() !== 0 ) {
274 $colorSpaceRegex =
'/' . preg_quote( $data[0],
'/' ) .
'/i';
275 if ( empty( preg_grep( $colorSpaceRegex, $colorSpaces ) ) ) {
280 $profileRegex =
'/' . preg_quote( $data[1],
'/' ) .
'/i';
281 if ( empty( preg_grep( $profileRegex, $oldProfileStrings ) ) ) {
286 $command = Shell::command( $exiftool,
287 '-overwrite_original',
288 '-icc_profile<=' . $profileFilepath,
295 if ( $result->getExitCode() !== 0 ) {
297 $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.
makeParamString( $params)
Merge a parameter array into a string appropriate for inclusion in filenames.stringto overrideto over...
validateParam( $name, $value)
Validate a thumbnail parameter at parse time.Return true to accept the parameter, and false to reject...
getScriptParams( $params)
to override
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.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.