MediaWiki  1.23.2
Jpeg.php
Go to the documentation of this file.
1 <?php
34  function getMetadata( $image, $filename ) {
35  try {
36  $meta = BitmapMetadataHandler::Jpeg( $filename );
37  if ( !is_array( $meta ) ) {
38  // This should never happen, but doesn't hurt to be paranoid.
39  throw new MWException( 'Metadata array is not an array' );
40  }
41  $meta['MEDIAWIKI_EXIF_VERSION'] = Exif::version();
42 
43  return serialize( $meta );
44  } catch ( MWException $e ) {
45  // BitmapMetadataHandler throws an exception in certain exceptional
46  // cases like if file does not exist.
47  wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" );
48 
49  /* This used to use 0 (ExifBitmapHandler::OLD_BROKEN_FILE) for the cases
50  * * No metadata in the file
51  * * Something is broken in the file.
52  * However, if the metadata support gets expanded then you can't tell if the 0 is from
53  * a broken file, or just no props found. A broken file is likely to stay broken, but
54  * a file which had no props could have props once the metadata support is improved.
55  * Thus switch to using -1 to denote only a broken file, and use an array with only
56  * MEDIAWIKI_EXIF_VERSION to denote no props.
57  */
58 
60  }
61  }
62 
70  public function rotate( $file, $params ) {
71  global $wgJpegTran;
72 
73  $rotation = ( $params['rotation'] + $this->getRotation( $file ) ) % 360;
74 
75  if ( $wgJpegTran && is_file( $wgJpegTran ) ) {
76  $cmd = wfEscapeShellArg( $wgJpegTran ) .
77  " -rotate " . wfEscapeShellArg( $rotation ) .
78  " -outfile " . wfEscapeShellArg( $params['dstPath'] ) .
79  " " . wfEscapeShellArg( $params['srcPath'] );
80  wfDebug( __METHOD__ . ": running jpgtran: $cmd\n" );
81  wfProfileIn( 'jpegtran' );
82  $retval = 0;
83  $err = wfShellExecWithStderr( $cmd, $retval );
84  wfProfileOut( 'jpegtran' );
85  if ( $retval !== 0 ) {
86  $this->logErrorForExternalProcess( $retval, $err, $cmd );
87 
88  return new MediaTransformError( 'thumbnail_error', 0, 0, $err );
89  }
90 
91  return false;
92  } else {
93  return parent::rotate( $file, $params );
94  }
95  }
96 }
JpegHandler\getMetadata
getMetadata( $image, $filename)
Get handler-specific metadata which will be saved in the img_metadata field.
Definition: Jpeg.php:34
ExifBitmapHandler
Stuff specific to JPEG and (built-in) TIFF handler.
Definition: ExifBitmap.php:30
MediaTransformError
Basic media transform error class.
Definition: MediaTransformOutput.php:409
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
$params
$params
Definition: styleTest.css.php:40
wfShellExecWithStderr
wfShellExecWithStderr( $cmd, &$retval=null, $environ=array(), $limits=array())
Execute a shell command, returning both stdout and stderr.
Definition: GlobalFunctions.php:3020
MWException
MediaWiki exception.
Definition: MWException.php:26
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
Exif\version
static version()
#-
Definition: Exif.php:580
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:933
wfEscapeShellArg
wfEscapeShellArg()
Windows-compatible version of escapeshellarg() Windows doesn't recognise single-quotes in the shell,...
Definition: GlobalFunctions.php:2705
JpegHandler
JPEG specific handler.
Definition: Jpeg.php:33
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
ExifBitmapHandler\getRotation
getRotation( $file)
On supporting image formats, try to read out the low-level orientation of the file and return the ang...
Definition: ExifBitmap.php:204
JpegHandler\rotate
rotate( $file, $params)
Definition: Jpeg.php:70
MediaHandler\logErrorForExternalProcess
logErrorForExternalProcess( $retval, $err, $cmd)
Log an error that occurred in an external process.
Definition: MediaHandler.php:766
ExifBitmapHandler\BROKEN_FILE
const BROKEN_FILE
Definition: ExifBitmap.php:31
BitmapMetadataHandler\Jpeg
static Jpeg( $filename)
Main entry point for jpeg's.
Definition: BitmapMetadataHandler.php:153
$e
if( $useReadline) $e
Definition: eval.php:66
$retval
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account incomplete not yet checked for validity & $retval
Definition: hooks.txt:237