27 private const SRGB_EXIF_COLOR_SPACE =
'sRGB';
28 private const SRGB_ICC_PROFILE_DESCRIPTION =
'sRGB IEC61966-2.1';
32 if ( !parent::normaliseParams( $image, $params ) ) {
35 if ( isset( $params[
'quality'] ) && !self::validateQuality( $params[
'quality'] ) ) {
43 if ( $name ===
'quality' ) {
44 return self::validateQuality( $value );
46 return parent::validateParam( $name, $value );
53 private static function validateQuality( $value ) {
54 return $value ===
'low';
60 $res = parent::makeParamString( $params );
61 if ( $res && isset( $params[
'quality'] ) ) {
62 $res =
"q{$params['quality']}-$res";
75 if ( preg_match(
'/q([^-]+)-(.*)$/', $str, $m ) ) {
77 if ( self::validateQuality( $v ) ) {
78 $res = parent::parseParamString( $m[2] );
84 $res = parent::parseParamString( $str );
91 $res = parent::getScriptParams( $params );
92 if ( isset( $params[
'quality'] ) ) {
93 $res[
'quality'] = $params[
'quality'];
102 if ( !is_array( $meta ) ) {
109 'width' => $meta[
'SOF'][
'width'] ?? 0,
110 'height' => $meta[
'SOF'][
'height'] ?? 0,
112 if ( isset( $meta[
'SOF'][
'bits'] ) ) {
113 $info[
'bits'] = $meta[
'SOF'][
'bits'];
116 unset( $meta[
'SOF'] );
117 $info[
'metadata'] = $meta;
120 wfDebug( __METHOD__ .
': ' . $e->getMessage() );
137 public function rotate( $file, $params ) {
140 $rotation = ( $params[
'rotation'] + $this->
getRotation( $file ) ) % 360;
142 if ( $jpegTran && is_executable( $jpegTran ) ) {
143 $command = Shell::command( $jpegTran,
153 if ( $result->getExitCode() !== 0 ) {
155 $result->getStdout(),
156 $command->__toString()
164 return parent::rotate( $file, $params );
174 $params = parent::sanitizeParamsForBucketing( $params );
177 unset( $params[
'quality'] );
189 $ret = parent::transformImageMagick( $image, $params );
195 if ( $useTinyRGBForJPGThumbnails ) {
208 $colorSpaces = [ self::SRGB_EXIF_COLOR_SPACE,
'-' ];
209 $profiles = [ self::SRGB_ICC_PROFILE_DESCRIPTION ];
214 if ( isset( $params[
'quality'] ) && $params[
'quality'] > 30 ) {
222 realpath( __DIR__ ) .
'/tinyrgb.icc'
241 array $oldProfileStrings, $profileFilepath
245 if ( !$exiftool || !is_executable( $exiftool ) ) {
249 $result = Shell::command(
252 '-ICC_Profile:ProfileDescription',
261 $data = explode(
"\t", trim( $result->getStdout() ), 3 );
263 if ( $result->getExitCode() !== 0 ) {
269 $colorSpaceRegex =
'/' . preg_quote( $data[0],
'/' ) .
'/i';
270 if ( !preg_grep( $colorSpaceRegex, $colorSpaces ) ) {
275 $profileRegex =
'/' . preg_quote( $data[1],
'/' ) .
'/i';
276 if ( !preg_grep( $profileRegex, $oldProfileStrings ) ) {
281 $command = Shell::command( $exiftool,
282 '-overwrite_original',
283 '-icc_profile<=' . $profileFilepath,
290 if ( $result->getExitCode() !== 0 ) {
292 $result->getStdout(),
293 $command->__toString()
304class_alias( JpegHandler::class,
'JpegHandler' );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
A class containing constants representing the names of configuration variables.
const UseTinyRGBForJPGThumbnails
Name constant for the UseTinyRGBForJPGThumbnails setting, for use with Config::get()
const JpegTran
Name constant for the JpegTran setting, for use with Config::get()
const Exiftool
Name constant for the Exiftool setting, for use with Config::get()